I am having a little trouble decrypting in C#, I keep getting an exception 'CryptographicException' exception being thrown with a message of 'Bad Data', does any one know what this means, here is the code below. It works for things I encrypted, but im trying decrypt something that i got from a device. A random number challenge, that is what is giving me the exception.
Code:
public string DecryptMessage(string encryptedBase64, string password)
{
TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider();
des.IV = new byte[8];
PasswordDeriveBytes pdb = new PasswordDeriveBytes(password, new byte[0]);
des.Key = pdb.CryptDeriveKey("RC2", "MD5", 128, new byte[8]);
byte[] encryptedBytes = ToByteArray(encryptedBase64);
MemoryStream ms = new MemoryStream(encryptedBase64.Length * 2);
CryptoStream decStream = new CryptoStream(ms, des.CreateDecryptor(),
CryptoStreamMode.Write);
decStream.Write(encryptedBytes, 0, encryptedBytes.Length);
decStream.FlushFinalBlock();
byte[] plainBytes = new byte[ms.Length];
ms.Position = 0;
ms.Read(plainBytes, 0, (int)ms.Length);
decStream.Close();
return Encoding.UTF8.GetString(plainBytes);
}