Re: RijndaelManaged problem...
From: Arun Moorthy[MS] (email@example.com)
- Next message: Andy Babiec: "Re: .net security vs. windows security"
- Previous message: Sridhar: "Setting custom file attributes"
- In reply to: Pieter Philippaerts: "RijndaelManaged problem..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "Arun Moorthy[MS]" <firstname.lastname@example.org> Date: Mon, 10 Feb 2003 14:23:56 -0800
If you are using v1 of the .Net framework, this is a bug with the padding
mode that has since been fixed (fix available in Everett).
If you wish to pad with zeros, the temporary workaround is to do the padding
manually. Paddingmode.None should really throw an exception since the data
is not a multiple of the block size (which it does in Everett).
Hope this helps.
"Pieter Philippaerts" <Pieter.email@example.com> wrote in message
> I'm working with the RijndaelManaged class, and I'm experiencing a problem
> with it. I've written a small example [see below] that explains my
> <BEGIN CODE>
> using System;
> using System.Text;
> using System.Security.Cryptography;
> RijndaelManaged rijnman = new RijndaelManaged();
> rijnman.Padding = PaddingMode.PKCS7;
> byte toEncrypt = Encoding.ASCII.GetBytes("Hello World! This is a test");
> byte encrypted =
> 0, toEncrypt.Length);
> byte decrypted =
> 0, encrypted.Length);
> Console.WriteLine("Encrypting " + toEncrypt.Length + " bytes");
> Console.WriteLine("Encrypted output = " + encrypted.Length + " bytes");
> Console.WriteLine("Decrypted bytes = " +
> <END CODE>
> If I run this code, I get the correct output:
> Encrypting 27 bytes
> Encrypted output = 32 bytes
> Decrypted bytes = Hello World! This is a test
> However, when I change the padding mode to PaddinMode.None or
> PaddingMode.Zeros, the output appears to be wrong:
> Encrypting 27 bytes
> Encrypted output = 16 bytes
> Decrypted bytes = Hello World! Thi
> Notice that the number of encrypted bytes is smaller than the number of
> unencrypted bytes [which is, of course, impossible].
> Does anyone know what's wrong with it? Why are the final bytes cut off?
> My first guess was that the ICryptoTransform returned by
> rijnman.CreateEncryptor() was unable to encrypt more than one block at
> if the PaddingMode was set to None or Zeros. However a call to
> CanTransformMultipleBlocks returns 'true', so it should be able to
> multiple blocks at once.
> Pieter Philippaerts