|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
SymmetricAlgorithm/CryptoStream screwed? "Length of data to encrypt is invalid"This happens when I used Rijndael 128 or TripleDES 192.... The following
code always throws "Length of the data to encrypt is invalid". ICryptoTransform trans = algorithm.CreateEncryptor(algorithm.Key, algorithm.IV); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, trans, CryptoStreamMode.Write); cs.Write(inputBytes, 0, inputBytes.Length); cs.FlushFinalBlock(); algorithm is a RijManaged or TDES object, inputBytes is a six-byte array in this case. Shouldn't this work? "ep" <re***@newgroup.only.please> wrote How did you setup the 'algorithm' object? In particular, what padding mode > This happens when I used Rijndael 128 or TripleDES 192.... The following > code always throws "Length of the data to encrypt is invalid". are you using? Your code works perfectly, unless I set the PaddingMode to 'None', in which case it is normal that the symmetric algorithm throws an exception. Regards, Pieter Philippaerts How inputBytes are encoding?
You must encoding the string to encrypt. To do this you can use the following code (for example): byte[] inputBytes = Encoding.UTF8.GetBytes(inputString); HTH ciauz |
|||||||||||||||||||||||