-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_mx_crypto.py
31 lines (20 loc) · 913 Bytes
/
test_mx_crypto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from base64 import b64encode, b64decode
from mx_crypto import MxCrypto
public_key, private_key = MxCrypto.generate_keys(1024)
attack_public_key, attack_private_key = MxCrypto.generate_keys(1024)
def test_decrypt():
msg = b"hello world!"
encrypted = MxCrypto.encrypt(public_key, msg)
original = MxCrypto.decrypt(private_key, encrypted)
assert msg == original
def test_sign():
msg = "Hello world!"
signature = MxCrypto.sign(private_key, msg)
verify = MxCrypto.verify(public_key, msg, signature)
altered_msg = b"Hello woorld!"
altered_verify = MxCrypto.verify(public_key, altered_msg, signature)
# I verify with another pub_key (pub_key doesn't correspond to priv_key that have created this signature).
fake_verify = MxCrypto.verify(attack_public_key, msg, signature)
assert verify == True
assert altered_verify == False
assert fake_verify == False