Forked from mevangelista-alvarado/read_pub_key_fiel.py
Created
June 18, 2021 16:50
-
-
Save ebarojas/45a776c0624bc0006ddcea3cce568f4e 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