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