Guest User

Untitled

a guest
Jul 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. from Crypto.Signature import PKCS1_v1_5
  2. from Crypto.Hash import SHA
  3. from Crypto.PublicKey import RSA
  4. message = b'Something secret'
  5.  
  6. random_gen = Crypto.Random.new().read
  7. print("Type of random_gen: {}".format(type(random_gen)))
  8. private_key = RSA.generate(1024, random_gen) # private key
  9. public_key = private_key.publickey() # public key
  10.  
  11. signer = PKCS1_v1_5.new(private_key) # signer which uses private key
  12. verifier = PKCS1_v1_5.new(public_key) # verifier which uses public key
  13.  
  14. h = SHA.new(message) # hash of message
  15. print("Hash: {}".format(h.hexdigest()))
  16.  
  17. signature = signer.sign(h) # sign hashed version of message
  18. print("Signature type = {}".format(type(signature)))
  19. print("Signature: {}".format(binascii.hexlify(signature).decode('ascii')))
  20.  
  21. print("Signature: {}".format(signature.decode('ascii')))
  22.  
  23. UnicodeDecodeError: 'ascii' codec can't decode byte 0x88 in position 2: ordinal not in range(128)
  24.  
  25. signature.hex()
Add Comment
Please, Sign In to add comment