Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Crypto.Signature import PKCS1_v1_5
- from Crypto.Hash import SHA
- from Crypto.PublicKey import RSA
- message = b'Something secret'
- random_gen = Crypto.Random.new().read
- print("Type of random_gen: {}".format(type(random_gen)))
- private_key = RSA.generate(1024, random_gen) # private key
- public_key = private_key.publickey() # public key
- signer = PKCS1_v1_5.new(private_key) # signer which uses private key
- verifier = PKCS1_v1_5.new(public_key) # verifier which uses public key
- h = SHA.new(message) # hash of message
- print("Hash: {}".format(h.hexdigest()))
- signature = signer.sign(h) # sign hashed version of message
- print("Signature type = {}".format(type(signature)))
- print("Signature: {}".format(binascii.hexlify(signature).decode('ascii')))
- print("Signature: {}".format(signature.decode('ascii')))
- UnicodeDecodeError: 'ascii' codec can't decode byte 0x88 in position 2: ordinal not in range(128)
- signature.hex()
Add Comment
Please, Sign In to add comment