RSA Cryptographic decryption Error: Invalid length for Base-64 character array
Article 1.
The program implements a function that serializes an object, passes it as a parameter to another page, and restores the object after it has been deserialized, but sometimes normal at run time, sometimes "invalid length of base-64 character array" error.
Looking up data on the internet, it is said that when using the Convert.tobase64string () method to encode a string Base64, you need to make the length of the parameter equal to 4 or 4 of the number of times, otherwise the "FormatException" exception will be thrown. But the parameters I use here are generated using the Convert.tobase64string () method, which is theoretically no problem. Then comparing the string a generated with convert.tobase64string () and the parameter string B used before deserializing convert.tobase64string (), we find that there is a difference between A and B, and the plus sign in a is a space. This is due to the Web page passing parameters, the plus sign is encoded into a space, but the decoding does not decode the space, the result is the string B is not correct, can not back code.
Confirm the problem is good to do, after the serialization string, using String.Replace ("+", "%2b") first space encoding, and then passed as a parameter to another page, so that the page in extracting parameters will be "%2b" decoded to a plus, the parameters are not different, The success of the deserialization is carried out.
The concrete implementation is this:
This is an error parameter in the link:
String comaddress;
comaddress = convert.tobase64string (System.Text.Encoding.Default.GetBytes (this. Text5.Value.Trim ()));
Add this to the following sentence:
Comaddress = comaddress. Replace ("+", "%2b");
Hope to be helpful to others too!
Article 2.
The most recent project, when passing parameters, is normal on Win2003, and throws "invalid length of base-64 character array" under Win7.
Compared to the convert.tobase64string () converted parameter discovery, + has become a space
So before passing the parameters, use replace ("+", "%2b"), the target page uses replace ("%2b", "+"), so the problem is solved
RSA Cryptographic decryption Error: Invalid length for Base-64 character array