First of all I want to wish everybody a Happy New Year!
Secondly I have come across a situation I find very confusing I am able to encrypt some data just fine. I save it to a file. In the same function I load that data from a file and decrypt it. All is fine.
I then load that data from the file in a different function and decrypt it. There are no errors, the same key and iv are used yet, at the beginning of the decrypted data one or two bytes are changed. The rest of the data decrypts fine. It seems to be in the first 16 bytes. For example
Raw data: (in hex)
3962326262666138353466386536371E
After encryption, saving to a file, loading from a file and decryption in the same function
3962326262666138353466386536371E
After loading from a file and decryption in a different function.
396232626266613835346638653F371E
You will notice the 14th byte is different. This position changes but always seems to be in the first 16 bytes.
The same code is used for decrypting in both cases as shown below
rafSig.Initialize(strFileDir,strSigName,True)
strHash = rafSig.ReadObject(0)
bArray = Bconv.HexToBytes(strHash)
bCArray = c.Decrypt(bArray,kg.key,True)
Log("Decrypted " & Bconv.HexFromBytes(bCArray))
After much testing every value is correct up until the c.Decrypt call. Any ideas why the byte changes?
PS: I forgot to mention that this does not happen all the time. Sometimes it decrypts correctly.