Skip to content

Instantly share code, notes, and snippets.

@mevangelista-alvarado
Created September 11, 2019 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mevangelista-alvarado/3434743f2abdaad7d72d41b96a4c7570 to your computer and use it in GitHub Desktop.
Save mevangelista-alvarado/3434743f2abdaad7d72d41b96a4c7570 to your computer and use it in GitHub Desktop.
from Crypto.PublicKey import RSA # nosec B413
from Crypto.Hash import SHA256 # nosec B413
# Read FIEL.cer
def read_fiel_cer(directory_file):
try:
public_key = None
with open(directory_file + '.cer', 'rb') as f:
public_key = RSA.import_key(f.read())
except Exception as e:
print(F'[ERROR read_fiel_cer] {e}, Type:{type(e)}')
return public_key
# verify sign
def verify_fiel_sign(message_utf8, signature_b64, public_key):
message_hash = SHA256.new(message_utf8)
signature = base64.b64decode(signature_b64)
try:
pkcs1_15.new(public_key).verify(message_hash, signature)
return True
except Exception as e:
print(F'[ERROR verify_fiel_sign] {e}, Type:{type(e)}')
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment