Encryption/Decryption Bad Data Exception
-
Hi, I am getting Cryptographic Exception while calling FlushFinalBlock method of CryptoStream after decrypting a buffer. Here is my code that decrypts the buffer.... DESCryptoServiceProvider des=new DESCryptoServiceProvider(); des.BlockSize=blockSize; des.Key=kDESKey; des.KeySize=64; des.Padding=PaddingMode.PKCS7; des.Mode=CipherMode.ECB; ICryptoTransform cryptoTransform=des.CreateDecryptor(); MemoryStream mem=new MemoryStream(); CryptoStream cryptoStream=new CryptoStream mem,cryptoTransform,CryptoStreamMode.Write); byte[] outputBuffer=new byte[cipherTextBytes.Length]; cryptoStream.Write (cipherTextBytes,0,cipherTextBytes.Length); cryptoStream.FlushFinalBlock(); outputBuffer=mem.ToArray(); cryptoStream.Close(); mem.Close(); return removeLength(outputBuffer); As soon as i call FlushFinalBlock it throws Cryptgraphic exception with message BadData. Please help me to solve this problem... Wasif Ehsan.