def encryption(): file = open(file_list[0], 'r') data_to_save = file.read() file.close() # PUT DATA in SECURE MODULE and ENCRYPT a = enc(message=data_to_save, key_path=KEY_PATH) bytes_like_object = a.encrypt() # bytes_like_object[0] # c1 (big binary data) # bytes_like_object[1] # c2 (small and tuple object) output_file = os.path.join(os.getcwd(), SAVE_PATH_HYBRID, file_list[0] + '.bin') with open(output_file, 'wb') as fp: fp.write(bytes_like_object[0]) fp.close() output_file = os.path.join(os.getcwd(), SAVE_PATH_HYBRID, 'c2.bin') with open(output_file, 'wb') as fp: fp.write(bytes_like_object[1][0]) fp.close() print('Created:', 'c2.bin') for f in file_list[1:]: # READ DATA TO SECURE file = open(f, 'r') data_to_save = file.read() file.close() # PUT DATA in SECURE MODULE and ENCRYPT a = enc(message=data_to_save, key_path=KEY_PATH) bytes_like_object = a.encrypt() # SAVE ENCRYPTED DATA TO .BIN output_file = os.path.join(os.getcwd(), SAVE_PATH_HYBRID, f + '.bin') with open(output_file, 'wb') as fp: fp.write(bytes_like_object[0]) fp.close() print('Created:', f + '.bin')
def encryption_rsa(): for f in file_list: # READ DATA TO SECURE file = open(f, 'r') data_to_save = file.read() file.close() # PUT DATA in SECURE MODULE and ENCRYPT a = enc(message=data_to_save, key_path=KEY_PATH) bytes_like_object = a.encrypt_RSA() # SAVE ENCRYPTED DATA TO .BIN output_file = os.path.join(os.getcwd(), SAVE_PATH, f + '.bin') with open(output_file, 'wb') as fp: fp.write(bytes_like_object) fp.close() print('Created:', f + '.bin')
def decryption_rsa(): for f in file_list: # READ DATA TO SECURE file = open(f + '.bin', 'rb') data_to_save = file.read() file.close() # PUT DATA in SECURE MODULE and DECRYPT a = enc(message=data_to_save, key_path=KEY_PATH) string_object = a.decrypt_RSA().decode() # SAVE DECRYPTED DATA TO .py output_file = os.path.join(os.getcwd(), SAVE_PATH, f) with open(output_file, 'w') as fp: fp.write(string_object) fp.close() print('Created:', f)
def decryption(): with open('c2.bin', 'rb') as fp: c2 = fp.read() fp.close() for f in file_list: # READ DATA TO SECURE file = open(f + '.bin', 'rb') data_to_save = file.read() file.close() # PUT DATA in SECURE MODULE and DECRYPT a = enc(c1=data_to_save, c2=c2, key_path=KEY_PATH) string_object = a.decrypt() # SAVE DECRYPTED DATA TO .py output_file = os.path.join(os.getcwd(), SAVE_PATH_HYBRID, f) with open(output_file, 'w') as fp: fp.write(string_object) fp.close() print('Created:', f)
from v1.RsaEncrypt import Encryptor as enc enc('test', encryption_size_multiplier=32).encrypt()