Hello,
I had some very simple encryption methods that I was using in .net 1.1 to encrypt data to a database then decrypt it for use in the application.
Now everytime I make a call to decrypt data I get an error "Bad Data"
//Byte array for encryption methods
private Byte[] KEY_64 = { 1, 50, 83, 1, 72, 9, 7, 32 };
private Byte[] IV_64 = { 5, 17, 68, 8, 4, 17, 2, 1 };
// returns DES encrypted string
public string Encrypt(string value)
{
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, cryptoProvider.CreateEncryptor(KEY_64, IV_64), CryptoStreamMode.Write);
StreamWriter sw = new StreamWriter(cs);
sw.Write(value);
sw.Flush();
cs.FlushFinalBlock();
ms.Flush();
// convert back to a string
return Convert.ToBase64String(ms.GetBuffer(), 0, Convert.ToInt32(ms.Length));
}
// returns DES decrypted string
public string Decrypt(string value)
{
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
Byte[] buffer = Convert.FromBase64String(value);
MemoryStream ms = new MemoryStream(buffer);
CryptoStream cs = new CryptoStream(ms, cryptoProvider.CreateDecryptor(KEY_64, IV_64), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cs);
return sr.ReadToEnd();
}
What has changed in .net 2.0 that doesn't allow decrypting this way anymore?
Thanks for your help.
I had some very simple encryption methods that I was using in .net 1.1 to encrypt data to a database then decrypt it for use in the application.
Now everytime I make a call to decrypt data I get an error "Bad Data"
//Byte array for encryption methods
private Byte[] KEY_64 = { 1, 50, 83, 1, 72, 9, 7, 32 };
private Byte[] IV_64 = { 5, 17, 68, 8, 4, 17, 2, 1 };
// returns DES encrypted string
public string Encrypt(string value)
{
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, cryptoProvider.CreateEncryptor(KEY_64, IV_64), CryptoStreamMode.Write);
StreamWriter sw = new StreamWriter(cs);
sw.Write(value);
sw.Flush();
cs.FlushFinalBlock();
ms.Flush();
// convert back to a string
return Convert.ToBase64String(ms.GetBuffer(), 0, Convert.ToInt32(ms.Length));
}
// returns DES decrypted string
public string Decrypt(string value)
{
DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
Byte[] buffer = Convert.FromBase64String(value);
MemoryStream ms = new MemoryStream(buffer);
CryptoStream cs = new CryptoStream(ms, cryptoProvider.CreateDecryptor(KEY_64, IV_64), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cs);
return sr.ReadToEnd();
}
What has changed in .net 2.0 that doesn't allow decrypting this way anymore?
Thanks for your help.