최상의 답변
python에서 파일을 암호화하는 데는 많은 옵션이 있습니다.
PyCrypto 라이브러리 사용 : PyCrypto는 보안 해시 함수 및 다양한 암호화 알고리즘 모음입니다. 먼저 PyCrypto를 설치합니다. CMD에서이 명령을 실행하여 패키지화
 pip install pycrypto 
AES 알고리즘을 사용한 파일 암호화 코드는 다음과 같습니다.
 import os, random, struct 
 from Crypto.Cipher import AES 
 def encrypt\_file(key, in\_filename, out\_filename=None, chunksize=64*1024): 
  """ Encrypts a file using AES (CBC mode) with the 
  given key. 
  key: 
  The encryption key - a string that must be 
  either 16, 24 or 32 bytes long. Longer keys 
  are more secure. 
  in\_filename: 
  Name of the input file 
  out\_filename: 
  If None, " 
  chunksize: 
  uses to read and encrypt the file. Larger chunk 
  sizes can be faster for some files and machines. 
  chunksize must be divisible by 16. 
  """ 
  if not out\_filename: 
  out\_filename = in\_filename + ".enc" 
  iv = "".join(chr(random.randint(0, 0xFF)) for i in range(16)) 
  encryptor = AES.new(key, AES.MODE\_CBC, iv) 
  filesize = os.path.getsize(in\_filename) 
  with open(in\_filename, "rb") as infile: 
  with open(out\_filename, "wb") as outfile: 
   
 outfile.write(struct.pack(" 
  outfile.write(iv) 
  while True: 
  chunk = infile.read(chunksize) 
  if len(chunk) == 0: 
  break 
  elif len(chunk) \% 16 != 0: 
  chunk += " " * (16 - len(chunk) \% 16) 
  outfile.write(encryptor.encrypt(chunk)) 
PyAesCrypt 사용 : AES256-CBC를 사용하여 파일을 암호화 및 해독하는 Python 3 개 파일 암호화 모듈
 pip install pyAesCrypt 
아래에 표시된 샘플 코드 :
 import pyAesCrypt 
 # encryption/decryption buffer size - 64K 
 bufferSize = 64 * 1024 
 password = "foopassword" 
 # encrypt 
 pyAesCrypt.encryptFile("data.txt", "data.txt.aes", password, bufferSize) 
 # decrypt 
 pyAesCrypt.decryptFile("data.txt.aes", "dataout.txt", password, bufferSize) 
Python Cryptography 라이브러리도 암호화를위한 좋은 옵션 일 수 있습니다.
Answer
  
python으로 파일을 암호화하는 가장 쉬운 방법은 암호화 모듈.
1. 설치 :
 pip/pip3 install cryptography 
2. 코드 :
“myvideo.mp4”