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.Len gth);
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.Re ad 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.
ICryptoTransfor m decryptor = myRijndael.Crea teDecryptor(key , IV);
encrypted=Conve rt.FromBase64St ring(Ink64Strin g);
MemoryStream msDecrypt = new MemoryStream(en crypted);
CryptoStream csDecrypt = new CryptoStream(ms Decrypt, decryptor,
CryptoStreamMod e.Read);
fromEncrypt = new byte[encrypted.Lengt h];
try
{
//problem is here!!
csDecrypt.Read( fromEncrypt, 0, fromEncrypt.Len gth);
}
catch (System.Excepti on exp)
{
MessageBox.Show (exp.Message,ex p.Source,Messag eBoxButtons.OK) ;
return String.Empty;
}
decryptedStr=te xtConverter.Get String(fromEncr ypt);
///remove \0 or null reference from the end of the string.
decryptedStr=de cryptedStr.Trim End(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.Len gth);
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.Re ad 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.
ICryptoTransfor m decryptor = myRijndael.Crea teDecryptor(key , IV);
encrypted=Conve rt.FromBase64St ring(Ink64Strin g);
MemoryStream msDecrypt = new MemoryStream(en crypted);
CryptoStream csDecrypt = new CryptoStream(ms Decrypt, decryptor,
CryptoStreamMod e.Read);
fromEncrypt = new byte[encrypted.Lengt h];
try
{
//problem is here!!
csDecrypt.Read( fromEncrypt, 0, fromEncrypt.Len gth);
}
catch (System.Excepti on exp)
{
MessageBox.Show (exp.Message,ex p.Source,Messag eBoxButtons.OK) ;
return String.Empty;
}
decryptedStr=te xtConverter.Get String(fromEncr ypt);
///remove \0 or null reference from the end of the string.
decryptedStr=de cryptedStr.Trim End(Char.Parse( "\0"));
//return the decrypted string.
return decryptedStr;
}
Comment