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(stri ng Source, string Key)
{
string ret = "";
try
{
// convert from Base64 to binary
byte[] bytIn =
System.Convert. FromBase64Strin g(Source);
// create a MemoryStream with the input
System.IO.Memor yStream ms = new
System.IO.Memor yStream(bytIn, 0, bytIn.Length);
byte[] bytKey = GetLegalKey(Key );
// set the private key
mobjCryptoServi ce.Key = bytKey;
mobjCryptoServi ce.IV = bytKey;
// create a Decryptor from the Provider Service
instance
ICryptoTransfor m encrypto =
mobjCryptoServi ce.CreateDecryp tor();
// create Crypto Stream that transforms a stream
using the decryption
CryptoStream cs = new CryptoStream(ms , encrypto,
CryptoStreamMod e.Read);
// read out the result from the Crypto Stream
System.IO.Strea mReader sr = new
System.IO.Strea mReader(cs);
ret = sr.ReadToEnd();
}
catch (Exception Ex)
{
MessageBox.Show (Ex.Message.ToS tring());
}
return ret;
}