1
Vote

Padding is invalid and cannot be removed

description

Hello,

I tried out the example code you provided on the source code.

For some reason the first two times I called the code. It seemed to work fine. I got 1 customer and 2 orders linked to that customer created from it. However, on the third time I ran the code, I got an error from CryptoHelper.cs line 111:
    byte[] decrypted = decryptor.TransformFinalBlock(
                decoded, 0, decoded.Length);

An exception of type 'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll but was not handled in user code

Additional information: Padding is invalid and cannot be removed.


On the call stack, it traced back to _GetCustomerObjInDb method where it tried to fetch the object.
customerObjInDb = (from c in dbCtx.TestCustomers
                           where c.SecurEntityThumbprint == thumbprintOfCustomer
                           select c).FirstOrDefault();
Please advise.

Thank you,

comments

frostshoxx wrote Nov 3, 2015 at 2:52 PM

Here is an additional information.

What I did was adding a string property "Name" to the Customer model class.

So the codes seem to work ok when I first create a new customer with unqiue email.

The first time it loads that newly created customer object works ok (separate web request).

But the second or later, I got the padding invalid error.

frostshoxx wrote Nov 3, 2015 at 2:57 PM

Actually, I found the issue.

I didn't put "virtual" on the property declaration of string Name. Putting virtual in the declaration solved the issue.