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,MessageBoxB uttons.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;
} 3 13973
I found the problem.
I passed wrong key and IV which caused an error.
"James" wrote: 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,MessageBoxB uttons.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'm not sure if you are having these problems, but I have solved a similar
problem that has been troubling me all afternoon....
If you are converting bytes to text using an ASCIIEncoder, or any other
8-bit encoder, it will only convert using 8-bits, i.e. a byte value of 129
will become 1!!
I had this problem because the MSDN sample uses an ASCII encoder! How
annoying!!!!! I hope this helps.
"James" wrote: I found the problem. I passed wrong key and IV which caused an error.
"James" wrote:
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,MessageBoxB uttons.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'm not sure if you are having these problems, but I have solved a similar
problem that has been troubling me all afternoon....
If you are converting bytes to text using an ASCIIEncoder, or any other
8-bit encoder, it will only convert using 8-bits, i.e. a byte value of 129
will become 1!!
I had this problem because the MSDN sample uses an ASCII encoder! How
annoying!!!!! I hope this helps.
"James" wrote: I found the problem. I passed wrong key and IV which caused an error.
"James" wrote:
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,MessageBoxB uttons.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; } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stingray |
last post by:
Are there any know problems with using a MemoryStream as a backing store for
a CryptoStream? I'm trying to simply encrypt and decrypt text in memory.
I'd like to create some simple methods to...
|
by: MattP |
last post by:
Ok, with the help of some examples found on the web and some minor
modifications on our own, we have a simple and working encrypt and
decrypt solution. It runs as a service, watches for files with...
|
by: Casey Watson |
last post by:
Hi :)
I'm having some major trouble with an XML Client/Server application that I
am writing. I am using NetworkStream with CryptoStream to Read and Write
XML between computers. Now, whenever I...
|
by: weixiang |
last post by:
Hi,
I want to use DES and CryptoStream to serialize a encrypted stream to a file
with a header "CRYPT". And I wrote these code:
To store:
FileStream fileStream = new FileStream(fileName,...
|
by: Daniel Weber |
last post by:
Hi!
In my code I create a CryptoStream around another stream of my own, with
CryptoStreamMode.Read. So I just can read from the CryptoStream. When I
close that CryptoStream, however, the...
|
by: pseudonym |
last post by:
To keep this short, assume the function working_test() works perfectly
(because it does), while
failing_test() is not. My GetCodec function returns a Stream (CryptoStream)
object wrapped around...
|
by: Burke Atilla |
last post by:
While encrypting data with DES through CryptoStream makes encrypted data bigger than original string. if we have 8 byte key and 8 byte of data then the mode is ECB. output encrypted data is 16 bytes...
|
by: TC |
last post by:
Hey All,
I posted this to the Crypto users group and forgot to add the VB.Net users
group. I apologize for any confusion.
I have been testing a try / catch / finally block and purposely...
|
by: Anil Gupte/iCinema.com |
last post by:
I am getting the following message and no, it is not even going to that
statement twice. Why is this happening?
System.NotSupportedException was caught
Message="FlushFinalBlock() method was...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |