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.
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.