123456789101112131415161718192021222324252627 |
- def encrypt(self):
- # create a cipher object
- cipher_object = AES.new(
- self.hashed_key_salt["key"], AES.MODE_CFB, self.hashed_key_salt["salt"]
- )
- self.abort() # if the output file already exists, remove it first
- input_file = open(self.user_file, "rb")
- output_file = open(self.encrypt_output_file, "ab")
- done_chunks = 0
- for piece in self.read_in_chunks(input_file, self.chunk_size):
- encrypted_content = cipher_object.encrypt(piece)
- output_file.write(encrypted_content)
- done_chunks += 1
- yield done_chunks / self.total_chunks * 100
- input_file.close()
- output_file.close()
- # clean up the cipher object
- del cipher_object
|