Created
September 11, 2019 15:50
-
-
Save mevangelista-alvarado/3434743f2abdaad7d72d41b96a4c7570 to your computer and use it in GitHub Desktop.
This file contains 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 # 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