Created
November 4, 2017 12:35
-
-
Save tlkahn/c811fb992b8248ace0e4906d527c6aa5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Crypto.PublicKey import RSA | |
from Crypto import Random | |
from Crypto.Signature import PKCS1_v1_5 | |
random_generator = Random.new().read | |
key = RSA.generate(1024, random_generator) # private key | |
public_key = key.publickey() | |
enc_data = public_key.encrypt('abcdefgh', 32) | |
key.decrypt(enc_data) # 'abcdefgh' | |
signer = PKCS1_v1_5.new(key) | |
sig = signer.sign('abcdefgh') | |
digest = SHA256.new() | |
digest.update('abcdefgh') # get hash of the string data | |
sig = signer.sign(digest) | |
verifier = PKCS1_v1_5.new(public_key) | |
verified = verifier.verify(digest, sig) # True | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment