This topic is now archived and is closed to further replies.

Decryption with Rijndael

This topic is 4947 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Don''t know how many of you have used the .NET encryption library before, but I''m having some serious trouble decrypting with the RijndaelManaged object. I have the following code:
byte[] cryptoBytes = Convert.FromBase64String(data);
MemoryStream ms = new MemoryStream(cryptoBytes);
CryptoStream cs = new CryptoStream(ms, RijndaelCrypt.CreateDecryptor(), CryptoStreamMode.Read);
byte[] plainText = new byte[cryptoBytes.Length];
cs.Read(plainText, 0, cryptoBytes.Length);
Whenever it executes cs.Read, an exception is thrown with the error:
PKCS7 padding is invalid and cannot be removed.
I have verified again and again that cryptoBytes contains the exact same encrypted bytes generated during encryption. I also verified that the Key, IV, Mode, and Padding are all the same from encryption. However, no matter what happens, this exception is always thrown. Is anyone familiar with why this could be happening? While I am sending the data over a network, I''ve verified it''s the same on both sides. Any insight would be appreciated. Also, sometimes when setting the RijndaelManaged.Key property, it throws an exception with the error "Bad Key." However this appears to happen randomly and nondeterministically, 1/3rd of the time I''d say. The key is generated by a RijndaelManaged object on another client and then assigned, so it certainly isn''t a bad key if it was generated directly by a RijndaelManaged object. However, this is the lesser of my two problems and more of a nuisance than a show-stopping bug

Share this post

Link to post
Share on other sites