Guest User

Untitled

a guest
Feb 25th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. from Crypto.Hash import SHA256
  2. from Crypto.PublicKey import RSA
  3. from Crypto import Random
  4.  
  5. random_generator = Random.new().read
  6.  
  7. #used to generate a keypair which contain a public and private key
  8. keyPair = RSA.generate(1024,random_generator)
  9. pubKey = keyPair.publicKey()
  10.  
  11. plainText = 'Hello World'
  12. hashA = SHA256.new(plainText).digest()
  13. digitalSignature = keyPair.sign(hashA,'')
  14.  
  15. print("Hash A: "+repr(hashA) + "n");
  16. print("Digital Signature: " + repr(digitalSignature) + "n")
  17.  
  18. #Bob receives the plainText and digitalSignature from Alice
  19. #plainTextChanged ='Hello World'
  20. hashB =SHA256.new(plainText).digest()
  21. print("Hash B: " + repr(hashB) + "n")
  22.  
  23. if(pubKey.verify(hashB, digitalSignature)):
  24. print("Match")
  25. else:
  26. print("No Match")
Add Comment
Please, Sign In to add comment