M
majarkus
Hi there,
I am writing an application that is reading encrypted data from a database.
The encrypted data was generated by an application developed in ColdFusion.
The data values were encrypted using the coldfusion 'encrypt' method.
The call to decrypt the values in the coldfusion app is:
decrypt(theValue, theKey, "AES","Base64")
No IV is supplied. (Does this mean the cipher mode is CBC?)
My code below produces a result, however the return values are rubbish.
Is anyone able to provide some advice?
Many thanks,
Mark.
public static string Decrypt1(string TextToBeDecrypted, string key)
{
RijndaelManaged RijndaelCipher = new RijndaelManaged();
RijndaelCipher.KeySize = 128;
RijndaelCipher.BlockSize = 128;
RijndaelCipher.Mode = CipherMode.CBC;
RijndaelCipher.Padding = PaddingMode.None;
RijndaelCipher.Key = Convert.FromBase64String(key);
byte[] EncryptedData = Convert.FromBase64String(TextToBeDecrypted);
ICryptoTransform Decryptor =
RijndaelCipher.CreateDecryptor(RijndaelCipher.Key, RijndaelCipher.Key);
MemoryStream memoryStream = new MemoryStream(EncryptedData);
CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor,
CryptoStreamMode.Read);
byte[] PlainText = new byte[EncryptedData.Length];
int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);
memoryStream.Close();
cryptoStream.Close();
string DecryptedData = Encoding.Unicode.GetString(PlainText, 0,
DecryptedCount);
return DecryptedData;
}
I am writing an application that is reading encrypted data from a database.
The encrypted data was generated by an application developed in ColdFusion.
The data values were encrypted using the coldfusion 'encrypt' method.
The call to decrypt the values in the coldfusion app is:
decrypt(theValue, theKey, "AES","Base64")
No IV is supplied. (Does this mean the cipher mode is CBC?)
My code below produces a result, however the return values are rubbish.
Is anyone able to provide some advice?
Many thanks,
Mark.
public static string Decrypt1(string TextToBeDecrypted, string key)
{
RijndaelManaged RijndaelCipher = new RijndaelManaged();
RijndaelCipher.KeySize = 128;
RijndaelCipher.BlockSize = 128;
RijndaelCipher.Mode = CipherMode.CBC;
RijndaelCipher.Padding = PaddingMode.None;
RijndaelCipher.Key = Convert.FromBase64String(key);
byte[] EncryptedData = Convert.FromBase64String(TextToBeDecrypted);
ICryptoTransform Decryptor =
RijndaelCipher.CreateDecryptor(RijndaelCipher.Key, RijndaelCipher.Key);
MemoryStream memoryStream = new MemoryStream(EncryptedData);
CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor,
CryptoStreamMode.Read);
byte[] PlainText = new byte[EncryptedData.Length];
int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);
memoryStream.Close();
cryptoStream.Close();
string DecryptedData = Encoding.Unicode.GetString(PlainText, 0,
DecryptedCount);
return DecryptedData;
}