Error by using of symmetric algorithms

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

By using of RijndaelManaged symmetric encryption algorithm you may get following error:

"Padding is invalid and cannot be removed."

By using of TrippleDES and TrippleDESCryptoServiceProvider you may get following exception:

"System.Security.Cryptography.CryptographicException: Bad Data"

Both exceptions are thrown when trying either to Read decrypted stream or to close it. This depends on how you implemented decryption.

After longer investigation I found that my problem is neither the key-size, iv-size and even not any kind of padding and any similar thing.
The problem is in both cases the place or time coordinate of setting of KEY and IV values. Just take a look on following two pictures:

image

 

 

image 

The first picture illustrates example which will FAIL. The second one is the good one. The CryptoStream has to be created after setting of the KEY and IV.
Note: Key-size used in this example was 32 bytes for Rijndaedel and 24 for TrippleDES. IV-size was 16-bytes for Rijndael and 8 bytes for TrippleDES.


Posted Jun 03 2008, 08:27 AM by Damir Dobric
Filed under:
developers.de is a .Net Community Blog powered by daenet GmbH.