G
gane kol
Hi
I am using DES algorithm. I am getting an error message in a few cases of
the querystring
Error Message : Length of the data to decrypt is invalid.
Error Method : System.String Decrypting(System.String)
Error Line: strDecrpt = sr.ReadToEnd();
QueryString Data:
---------------------
id1: IVUTMOv8Hno0eG0=
But it works for
id1: 02FPObSRAf6bARvt5FM3wA==
Any ideas appreciated,
Thanks
Gane
code
------
public string Encrypting(string Source)
{
if (System.Configuration.ConfigurationSettings.AppSettings["ENV"] != "DEV")
{
string Key;
string strEncrpt = null;
if ((Source != "") && (Source != null))
{
int i = 0;
Key = CRYPTO_KEY;
try
{
byte[] bytIn = System.Text.ASCIIEncoding.ASCII.GetBytes(Source);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
byte[] bytKey = GetLegalKey(Key);
mobjCryptoService.Key = bytKey;
mobjCryptoService.IV = bytKey;
ICryptoTransform encrypto = mobjCryptoService.CreateEncryptor();
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
cs.Write(bytIn, 0, bytIn.Length);
cs.FlushFinalBlock();
byte[] bytOut = ms.GetBuffer();
for (i = 8; i <= bytOut.Length - 1; i++)
{
if ((bytOut == 0))
{
goto exitForStatement0;
}
}
exitForStatement0: ;
strEncrpt = System.Convert.ToBase64String(bytOut, 0, i);
return strEncrpt;
}
catch (Exception Exp)
{
throw Exp;
}
}
else
{return strEncrpt; }
}
return Source;
}
public string Decrypting(string Source)
{
if (System.Configuration.ConfigurationSettings.AppSettings["ENV"] != "DEV")
{
string strDecrpt = null;
if ((Source != "") && (Source != null))
{
string Key;
Key = CRYPTO_KEY;
Source = Source.Replace(" ","+");
char padChar = Convert.ToChar("=");
int length = Source.Length;
if (length % 4 > 0)
{
Source = Source.PadRight(length + (4-(length % 4)),padChar);
}
try
{
byte[] bytIn = System.Convert.FromBase64String(Source);
System.IO.MemoryStream ms = new System.IO.MemoryStream(bytIn, 0,
bytIn.Length);
byte[] bytKey = GetLegalKey(Key);
mobjCryptoService.Key = bytKey;
mobjCryptoService.IV = bytKey;
ICryptoTransform encrypto = mobjCryptoService.CreateDecryptor();
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Read);
System.IO.StreamReader sr = new System.IO.StreamReader(cs);
strDecrpt = sr.ReadToEnd();
return strDecrpt;
}
catch (Exception Exp)
{
throw Exp;
}
}
else
{return strDecrpt;}
}
return Source;
}
I am using DES algorithm. I am getting an error message in a few cases of
the querystring
Error Message : Length of the data to decrypt is invalid.
Error Method : System.String Decrypting(System.String)
Error Line: strDecrpt = sr.ReadToEnd();
QueryString Data:
---------------------
id1: IVUTMOv8Hno0eG0=
But it works for
id1: 02FPObSRAf6bARvt5FM3wA==
Any ideas appreciated,
Thanks
Gane
code
------
public string Encrypting(string Source)
{
if (System.Configuration.ConfigurationSettings.AppSettings["ENV"] != "DEV")
{
string Key;
string strEncrpt = null;
if ((Source != "") && (Source != null))
{
int i = 0;
Key = CRYPTO_KEY;
try
{
byte[] bytIn = System.Text.ASCIIEncoding.ASCII.GetBytes(Source);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
byte[] bytKey = GetLegalKey(Key);
mobjCryptoService.Key = bytKey;
mobjCryptoService.IV = bytKey;
ICryptoTransform encrypto = mobjCryptoService.CreateEncryptor();
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write);
cs.Write(bytIn, 0, bytIn.Length);
cs.FlushFinalBlock();
byte[] bytOut = ms.GetBuffer();
for (i = 8; i <= bytOut.Length - 1; i++)
{
if ((bytOut == 0))
{
goto exitForStatement0;
}
}
exitForStatement0: ;
strEncrpt = System.Convert.ToBase64String(bytOut, 0, i);
return strEncrpt;
}
catch (Exception Exp)
{
throw Exp;
}
}
else
{return strEncrpt; }
}
return Source;
}
public string Decrypting(string Source)
{
if (System.Configuration.ConfigurationSettings.AppSettings["ENV"] != "DEV")
{
string strDecrpt = null;
if ((Source != "") && (Source != null))
{
string Key;
Key = CRYPTO_KEY;
Source = Source.Replace(" ","+");
char padChar = Convert.ToChar("=");
int length = Source.Length;
if (length % 4 > 0)
{
Source = Source.PadRight(length + (4-(length % 4)),padChar);
}
try
{
byte[] bytIn = System.Convert.FromBase64String(Source);
System.IO.MemoryStream ms = new System.IO.MemoryStream(bytIn, 0,
bytIn.Length);
byte[] bytKey = GetLegalKey(Key);
mobjCryptoService.Key = bytKey;
mobjCryptoService.IV = bytKey;
ICryptoTransform encrypto = mobjCryptoService.CreateDecryptor();
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Read);
System.IO.StreamReader sr = new System.IO.StreamReader(cs);
strDecrpt = sr.ReadToEnd();
return strDecrpt;
}
catch (Exception Exp)
{
throw Exp;
}
}
else
{return strDecrpt;}
}
return Source;
}