You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import pytest
|
|
|
|
|
|
|
|
from tool import PriKeyHelper
|
|
|
|
from tool.asymmetric import RSA
|
|
|
|
|
|
|
|
|
|
|
|
def test_encrypt():
|
|
|
|
key = PriKeyHelper.getUserKey()
|
|
|
|
message = b"Hello, this is a secret message."
|
|
|
|
# 打印keys
|
|
|
|
print(key[0])
|
|
|
|
print(key[1])
|
|
|
|
|
|
|
|
# 加密消息
|
|
|
|
encrypted = RSA.encrypt_message(message, key[1])
|
|
|
|
print(f"Encrypted: {encrypted}")
|
|
|
|
|
|
|
|
# 解密消息
|
|
|
|
decrypted = RSA.decrypt_message(encrypted, key[0])
|
|
|
|
print(f"Decrypted: {decrypted}")
|
|
|
|
|
|
|
|
|
|
|
|
def test_sign():
|
|
|
|
|
|
|
|
key = PriKeyHelper.getUserKey()
|
|
|
|
message = b"This is a signed message."
|
|
|
|
# 打印keys
|
|
|
|
print(key[0])
|
|
|
|
print(key[1])
|
|
|
|
|
|
|
|
|
|
|
|
# 签名消息
|
|
|
|
signature = RSA.sign_message(message, key[0])
|
|
|
|
print(f"Signature: {signature}")
|
|
|
|
|
|
|
|
# 验证签名
|
|
|
|
is_valid = RSA.verify_signature(message, signature, key[1])
|
|
|
|
print(f"Is Signature Valid? {is_valid}")
|
|
|
|
assert is_valid == True
|