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 callback(path): try: # Save proxy = self.proxy.current self.aes_key = AESCipher.generate_key() remote_uri = str(path) new_file_info = FileInfo( name=self.data_name.value, data_type='stream', proxy=proxy, remote_type='stream', remote_uri=remote_uri, public_key=wallet.market_client.public_key, is_published=False, created=func.current_timestamp(), aes_key=self.aes_key) fs.add_file(new_file_info) self._id = new_file_info.id encrypted_key = RSACipher.encrypt(self.aes_key) encrypted_key = Encoder.bytes_to_base64_str(encrypted_key) wallet.market_client.upload_file_info(None, None, 0, self._id, 'stream', json.dumps(remote_uri), self.data_name.value, encrypted_key) path = json.loads(path) self.uploaded.emit(path) except Exception as err: logger.error(err)
def encrypt_file(file_in_path, file_out_path): new_key = AESCipher.generate_key() encrypter = AESCipher(new_key) encrypter.encrypt(file_in_path, file_out_path) return new_key
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])