def decrypt_file_aes(file_path, aes_key): decrypted_aes_key = RSACipher.decrypt(aes_key) print('In Decrypt file aes:' + str(len(decrypted_aes_key))) decrypter = AESCipher(decrypted_aes_key) decrypted_path = file_path + "_decrypted" decrypter.decrypt(file_path, decrypted_path) return decrypted_path
def decrypt_file(file_in_path, file_out_path): session = get_session() aes_key = session.query( FileInfo.aes_key).filter(FileInfo.path == file_in_path).first()[0] decrypter = AESCipher(aes_key) decrypter.decrypt(file_in_path, file_out_path)
import os.path as osp import subprocess import cpchain from cpchain.crypto import AESCipher key = b'\xaf\x1a8\x9f_=\xac\xb5"$.\xd2\xcb\xdf\xfb\xeb' cipher = AESCipher(key) fpath = osp.join(cpchain.root_dir, "tools/assets/shakespeare.txt") outpath = osp.join(cpchain.root_dir, "tools/crypto/_local_en-sp.txt") cipher.encrypt(fpath, outpath) d = cipher.get_digest(outpath) print("valid" if cipher.is_valid(outpath, d) else "invalid") newpath = osp.join(cpchain.root_dir, "tools/crypto/_local_de-sp.txt") cipher.decrypt(outpath, newpath) subprocess.run(['sha256sum', fpath]) subprocess.run(['sha256sum', newpath])