EncryptionDecryption_2.py 668 B

123456789101112131415161718
  1. def decrypt(self, key, filename):
  2. outFile = os.path.join(os.path.dirname(filename),
  3. os.path.basename(filename).replace("(Secured)", ""))
  4. print(outFile)
  5. chunksize = 128 * 1024
  6. with open(filename, "rb") as infile:
  7. filesize = infile.read(16)
  8. IV = infile.read(16)
  9. decryptor = AES.new(key, AES.MODE_CBC, IV)
  10. with open(outFile, "wb") as outfile:
  11. while True:
  12. chunk = infile.read(chunksize)
  13. if len(chunk) == 0:
  14. break
  15. outfile.write(decryptor.decrypt(chunk))
  16. outfile.truncate(int(filesize))
  17. return outFile