Legjobb válasz
Sok lehetőség van egy fájl titkosítására a Pythonban.
A PyCrypto könyvtár használata: A PyCrypto biztonságos hash függvények és különféle titkosítási algoritmusok gyűjteménye. Először telepítse a PyCrypto programot csomagot a parancs futtatásával CMD-n
 pip install pycrypto 
Az AES algoritmust használó fájl titkosítás kódja az alábbiakban látható
 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)) 
A PyAesCrypt használata: Python három fájl titkosítási modul, amely AES256-CBC-t használ a fájlok titkosításához és visszafejtéséhez
 pip install pyAesCrypt 
Az alább látható mintakód:
 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) 
A Python kriptográfiai könyvtár jó lehetőség lehet a titkosításhoz is
Válasz
  
A fájlok python segítségével történő titkosításának legegyszerűbb módja a ">