import sys from cryptography.hazmat.primitives import serialization, hashes from cryptography.hazmat.primitives.asymmetric import rsa, padding def encryptFile(public_key, text): ciphertext = public_key.encrypt( text, padding.OAEP( mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None ) ) return ciphertext def load_public_key(file): with open(file, 'rb') as key_file: public_key = serialization.load_pem_public_key( key_file.read(), ) return public_key