Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pbteja1998/a6e5a4e77b90ebfb8f04a291b5cbfd34 to your computer and use it in GitHub Desktop.
Save pbteja1998/a6e5a4e77b90ebfb8f04a291b5cbfd34 to your computer and use it in GitHub Desktop.
def sign_data(private_key, hashed_data):
'''
param: private_key
param: hashed_data SHA256 hash of data to be signed
return: base64 encoded signature
'''
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
from base64 import b64encode
key = private_key
rsakey = RSA.importKey(key)
signer = PKCS1_v1_5.new(rsakey)
sign = signer.sign(hashed_data)
return b64encode(sign)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment