123456789101112131415161718 |
- def decrypt(self, key, filename):
- outFile = os.path.join(os.path.dirname(filename),
- os.path.basename(filename).replace("(Secured)", ""))
- print(outFile)
- chunksize = 128 * 1024
- with open(filename, "rb") as infile:
- filesize = infile.read(16)
- IV = infile.read(16)
- decryptor = AES.new(key, AES.MODE_CBC, IV)
- with open(outFile, "wb") as outfile:
- while True:
- chunk = infile.read(chunksize)
- if len(chunk) == 0:
- break
- outfile.write(decryptor.decrypt(chunk))
- outfile.truncate(int(filesize))
- return outFile
|