sio-2425/delivery1/cryptLib/decryptionFuncts.py

27 lines
567 B
Python

import sys
from cryptography.hazmat.primitives import serialization, hashes
from cryptography.hazmat.primitives.asymmetric import rsa, padding
def decryptFile(private_key, cipher_text):
plain_text = private_key.decrypt(
cipher_text,
padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA256()),
algorithm=hashes.SHA256(),
label=None
)
)
return plain_text
def load_private_key(file, paswd=None):
with open(file, 'rb') as key_file:
private_key = serialization.load_pem_private_key(
key_file.read(),
password=paswd,
)
return private_key