forked from sahilchadha1991/cryptoExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assym.py
26 lines (20 loc) · 865 Bytes
/
assym.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
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import dsa
from pprint import pprint
private_key = dsa.generate_private_key(key_size=1024,
backend=default_backend())
private_key1 = dsa.generate_private_key(key_size=1024,
backend=default_backend())
print("private key is", private_key)
print("one more key", repr(private_key))
print("zzz", private_key.__str__())
signer = private_key.signer(hashes.SHA256())
data = b"this is some data I'd like to sign"
signer.update(data)
signature = signer.finalize()
public_key = private_key.public_key()
print("public key is", public_key)
verifier = public_key.verifier(signature, hashes.SHA256())
verifier.update(data)
verifier.verify()