Java garbled and transcoding problems

Source: Internet
Author: User

In a project, encountered an interesting problem, after invoking a third-party interface callback local code, the encrypted request parameter decryption and transcoding, one of the decoding method is invalid, another decoding method valid, what solution? :


1. Encrypt a string when invoking a third-party interface:

String str = "AKDFJLKSJFDLJSDLFSLFLD";

(New Base64encoder ()). Encodebuffer (Str.getbytes ());


2, synchronous callback local code when decrypting and transcoding the string, using the following transcoding scheme is not a problem, while the asynchronous callback local code when decrypting and transcoding the string, using the following transcoding scheme has the problem:

String Merpriv = Request ("Merpriv");

String newmerpriv = new String ((New Base64decoder ()). Decodebuffer (Merpriv));

Newmerpriv = Urldecoder.decode (Newmerpriv, "UTF-8"). Trim ();


3, the asynchronous callback local code when decrypting and transcoding the string, using the following transcoding scheme no problem:

String Merpriv = Request ("Merpriv");

String newmerpriv = new String ((New Base64decoder ()). Decodebuffer (Merpriv));

Newmerpriv = new String (newmerpriv.getbytes ("iso-8859-1"), "UTF-8");


Java garbled and transcoding problems

Related Article

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.