G
Guest
Hi,
I am developing a ActiveX Control which will be used in a web page.
The control will encrypt some value then decrypt it when the web page opens
next time.
I tested the control in a windows application and it works fine and no error
jumps.
However, when I tried to use it in a web page, problems came.
There is no problem for encrypting but the decrypting can't be finished.
The error jumped from the line below
csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
and the error message reads as below:
PKCS7 padding is invalid and cannot be removed.
I tested again in the windows application but I couldn't trigger the error.
Does any one know why this CryptoStream.Read Method behaves differently
in a web browser?
Please see code details below.
protected string DecryptInk(byte[] key,byte[] IV,String Ink64String)
{
ASCIIEncoding textConverter= new ASCIIEncoding();
RijndaelManaged myRijndael=new RijndaelManaged();
byte[] fromEncrypt;
byte[] encrypted;
string decryptedStr;
//Get a decryptor that uses the same key and IV as the encryptor.
ICryptoTransform decryptor = myRijndael.CreateDecryptor(key, IV);
encrypted=Convert.FromBase64String(Ink64String);
MemoryStream msDecrypt = new MemoryStream(encrypted);
CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor,
CryptoStreamMode.Read);
fromEncrypt = new byte[encrypted.Length];
try
{
//problem is here!!
csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
}
catch (System.Exception exp)
{
MessageBox.Show(exp.Message,exp.Source,MessageBoxButtons.OK);
return String.Empty;
}
decryptedStr=textConverter.GetString(fromEncrypt);
///remove \0 or null reference from the end of the string.
decryptedStr=decryptedStr.TrimEnd(Char.Parse("\0"));
//return the decrypted string.
return decryptedStr;
}
I am developing a ActiveX Control which will be used in a web page.
The control will encrypt some value then decrypt it when the web page opens
next time.
I tested the control in a windows application and it works fine and no error
jumps.
However, when I tried to use it in a web page, problems came.
There is no problem for encrypting but the decrypting can't be finished.
The error jumped from the line below
csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
and the error message reads as below:
PKCS7 padding is invalid and cannot be removed.
I tested again in the windows application but I couldn't trigger the error.
Does any one know why this CryptoStream.Read Method behaves differently
in a web browser?
Please see code details below.
protected string DecryptInk(byte[] key,byte[] IV,String Ink64String)
{
ASCIIEncoding textConverter= new ASCIIEncoding();
RijndaelManaged myRijndael=new RijndaelManaged();
byte[] fromEncrypt;
byte[] encrypted;
string decryptedStr;
//Get a decryptor that uses the same key and IV as the encryptor.
ICryptoTransform decryptor = myRijndael.CreateDecryptor(key, IV);
encrypted=Convert.FromBase64String(Ink64String);
MemoryStream msDecrypt = new MemoryStream(encrypted);
CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor,
CryptoStreamMode.Read);
fromEncrypt = new byte[encrypted.Length];
try
{
//problem is here!!
csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
}
catch (System.Exception exp)
{
MessageBox.Show(exp.Message,exp.Source,MessageBoxButtons.OK);
return String.Empty;
}
decryptedStr=textConverter.GetString(fromEncrypt);
///remove \0 or null reference from the end of the string.
decryptedStr=decryptedStr.TrimEnd(Char.Parse("\0"));
//return the decrypted string.
return decryptedStr;
}