0

I have been trying to write a code which will encrypt and then decrypt the files using AES . IV is a randomly generated and keys are derived on the basis of file name which will be encrypted/decrypted. But the issue is that the code works fine for a common key for all files but if generate different keys for different files, files get corrupted after decryption. I'm adding two links for encryption and decryption code.

Encryption code

Decryption code

I am writing the keys to a file while encryption and then reading it from that file during decryption. Also using sha256 to make sure that keys are 16 bit or multiple of 16 bit.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • Not a 100% sure, but pretty confident that your problem has something to do with the way you write ('w') and read ('b') your passwords. Have you tried printing the keys (as e.g. hex) right before encryption and decryption? I'm almost certain that they won't agree. – nostradamus Jan 09 '20 at 09:16
  • I printed the keys just to debug it and it prints them pretty well. – Mritunjay Kumar Jan 09 '20 at 11:47
  • https://photos.app.goo.gl/vuFUU37a6AQD6y6q8 – Mritunjay Kumar Jan 09 '20 at 11:47

0 Answers0