#!/usr/bin/env python3 import secrets from Cryptodome.Cipher import AES import base64 import struct import subprocess import binascii def encrypt_file(filename_in, chunk_size=1000000//16): file_id = secrets.token_urlsafe(22) auth_secret = secrets.token_bytes(16) key = secrets.token_bytes(16) data_nonce = secrets.token_bytes(8) token_cipher = AES.new(auth_secret, AES.MODE_GCM) ciphertext, token_tag = token_cipher.encrypt_and_digest(key) token = base64.b64encode(ciphertext) with open(f'{file_id}.enc', 'wb') as fout, open(filename_in, 'rb') as fin: fout.write(token_cipher.nonce) # 16 bytes fout.write(token_tag) # 16 bytes fout.write(auth_secret) # 16 bytes fout.write(data_nonce) # 8 bytes cipher = AES.new(key, AES.MODE_CTR, initial_value=struct.pack('