Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

padding is invalid and cannot be removed

40 views
Skip to first unread message

Yogesh Dige

unread,
Jan 7, 2012, 12:42:15 AM1/7/12
to
Hi All

I am using the AES decription with padding1 but when i am going to
decrypt the file which i got from my clinet i am getting the error
"padding is invalid and cannot be removed".I goggled about it also
and found that to give proper Key and vector values. but still i am
getting the same error even though i put proper values of vector IV
and Key


Yogesh Dige

unread,
Jan 9, 2012, 9:29:38 AM1/9/12
to
here is the code for ref:

RijndaelManaged rijndaelCipher = new RijndaelManaged();
rijndaelCipher.Mode = CipherMode.ECB;
rijndaelCipher.Padding = PaddingMode.PKCS7;
string sIV = null;
sIV = "0000000000000000"; //16 Zeros.
// sIV = "0";
byte[] IVBytes = Encoding.UTF8.GetBytes(sIV);
rijndaelCipher.KeySize = 0x80;
rijndaelCipher.BlockSize = 0x80;
//Decoding
byte[] encryptedData =
Convert.FromBase64String(textToDecrypt);
byte[] pwdBytes = Encoding.UTF8.GetBytes(key);
byte[] keyBytes = new byte[0x10];
int len = pwdBytes.Length;
if (len > keyBytes.Length)
{
len = keyBytes.Length;
}
Array.Copy(pwdBytes, keyBytes, len);
rijndaelCipher.Key = keyBytes;
// rijndaelCipher.IV = keyBytes;
rijndaelCipher.IV = IVBytes;
byte[] plainText =
rijndaelCipher.CreateDecryptor().TransformFinalBlock(encryptedData, 0,
encryptedData.Length);
string sDecode =
System.Text.ASCIIEncoding.ASCII.GetString(plainText);
return sDecode;
0 new messages