Encrypt/Decrypt File Upload

Topics: Cryptography Application Block
Jan 7, 2007 at 6:19 AM
I'm attempting to encrypt and decrypt a file using the Cryptography Application Block and I am running into a bit of a problem. Using this code:

Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Cryptographer.EncryptSymmetric(symmProvider, bytesToEncrypt)

Returns a byte array which I store in a table.

However, when I try to use:

Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.Cryptographer.DecryptSymmetric(symmProvider, bytesToDecrypt)

It returns an exception: "Padding is invalid and cannot be removed."

In the old world, I think set the padding for Rijndael to None and I think that solved the problem. Am I missing something? Should I use the provider in another fashion?

Jan 7, 2007 at 7:28 AM
Please disregard. When retrieving the encrypted value from the database, I was sizing the returning byte array by the pre-encrypted file size and not the encrypted file size - hence the error message.