Transfer encryption on Android and server side

Source: Internet
Author: User
Tags md5 encryption

1, must find a common on Android and JDK encryption algorithm, later found http://www.cnblogs.com/hjtdlx/p/3926141.html this article, try it, it can be used.

2, Android and server side of the transmission in JSON format, in addition to encryption to verify whether or not modified. Transfer format:

{PARAMS:XXX,SIGN:XXX}



Where the params is DES3 encrypted JSON data, sign is the original JSON data MD5 value. In this way, after the data received the Des decryption, and then the decrypted JSON data MD5, and passed the sign to know that is not the original data.

Related code for encryption

/** * Encryption processing * @param data JSON data * @return * @throws Exception */private string encodesign (String data) throws Exception{js Onobject jsonobject = new Jsonobject () jsonobject.put ("params", Des3.encode (data)); Jsonobject.put ("Sign", Md5util.encryptpassword (data)); return data = Jsonobject.tojsonstring ();}



When you decrypt it, just handle it in a unified interceptor.

Private Jsonobject decodesign (jsonobject result) {  try {String params = Des3.decode (result.getstring ("params")); String sign = result.getstring ("sign"), if (Sign.equals (Md5util.encryptpassword (params))) {result = Jsonobject.parseobject (params);} else{throw new RuntimeException ("Validate sign Fail"),        } catch (Exception e) {e.printstacktrace ();} return result;}



3, the development of the time found MD5 encryption results inconsistent, found in the method of MD5 encryption String.getbytes () does not specify the character set encoding, Android and server side of the encoding format is not the same result.

Transfer encryption on Android and server side

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.