Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
def sign_data(private_key_loc, data):
param: private_key_loc Path to your private key
param: package Data to be signed
return: base64 encoded signature
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
from Crypto.Hash import SHA256
from base64 import b64encode, b64decode
key = open(private_key_loc, "r").read()
rsakey = RSA.importKey(key)
signer =
digest =
# It's being assumed the data is base64 encoded, so it's decoded before updating the digest
sign = signer.sign(digest)
return b64encode(sign)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment