EncrypC_3.py 776 B

1234567891011121314151617181920212223242526
  1. def encrypt(self):
  2. # create a cipher object
  3. cipher_object = AES.new(
  4. self.hashed_key_salt["key"], AES.MODE_CFB, self.hashed_key_salt["salt"]
  5. )
  6. self.abort() # if the output file already exists, remove it first
  7. input_file = open(self.user_file, "rb")
  8. output_file = open(self.encrypt_output_file, "ab")
  9. done_chunks = 0
  10. for piece in self.read_in_chunks(input_file, self.chunk_size):
  11. encrypted_content = cipher_object.encrypt(piece)
  12. output_file.write(encrypted_content)
  13. done_chunks += 1
  14. yield done_chunks / self.total_chunks * 100
  15. input_file.close()
  16. output_file.close()
  17. # clean up the cipher object
  18. del cipher_object