Это код Python, который я использовал раньше:
Код: Выделить всё
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
import os
def encrypt_video(input_file, output_file, key, nonce):
algorithm = algorithms.ChaCha20(key, nonce)
cipher = Cipher(algorithm, mode=None, backend=default_backend())
encryptor = cipher.encryptor()
with open(input_file, 'rb') as f_in, open(output_file, 'wb') as f_out:
while chunk := f_in.read():
encrypted_chunk = encryptor.update(chunk)
f_out.write(encrypted_chunk)
f_out.write(encryptor.finalize())
def decrypt_video(input_file, output_file, key, nonce):
algorithm = algorithms.ChaCha20(key, nonce)
cipher = Cipher(algorithm, mode=None, backend=default_backend())
decryptor = cipher.decryptor()
with open(input_file, 'rb') as f_in, open(output_file, 'wb') as f_out:
while chunk := f_in.read():
decrypted_chunk = decryptor.update(chunk)
f_out.write(decrypted_chunk)
f_out.write(decryptor.finalize())
key = os.urandom(32)
nonce = os.urandom(16)
encrypt_video('input.mp4', 'encrypted_video.mp4', key, nonce)
decrypt_video('encrypted_video.mp4', 'decrypted_video.mp4', key, nonce)
Подробнее здесь: https://stackoverflow.com/questions/785 ... -encrypt-a