Hi,
I need your help, the following code is not working, ret = sr.ReadToEnd()
throws the message error : Length of the data to decrypt is invalid.
Any idea ?
thank you
public string Decrypting(string Source, string Key)
{
string ret = "";
try
{
// convert from Base64 to binary
byte[] bytIn =
System.Convert.FromBase64String(Source);
// create a MemoryStream with the input
System.IO.MemoryStream ms = new
System.IO.MemoryStream(bytIn, 0, bytIn.Length);
byte[] bytKey = GetLegalKey(Key);
// set the private key
mobjCryptoService.Key = bytKey;
mobjCryptoService.IV = bytKey;
// create a Decryptor from the Provider Service
instance
ICryptoTransform encrypto =
mobjCryptoService.CreateDecryptor();
// create Crypto Stream that transforms a stream
using the decryption
CryptoStream cs = new CryptoStream(ms, encrypto,
CryptoStreamMode.Read);
// read out the result from the Crypto Stream
System.IO.StreamReader sr = new
System.IO.StreamReader(cs);
ret = sr.ReadToEnd();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message.ToString());
}
return ret;
}