RSA Cryptographic decryption Error: Invalid length for Base-64 character array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.