参考:
http://www.androidsnippets.com/encrypt-decrypt-between-android-and-php
注意:密钥和填充函数的类型和值.
附加动态密钥解决方案:
每次会话生成一个token外反回一个关联的密钥,客户端和服务器端的通讯基于这个密钥.
原理简单,可以降低危害。即使代码反编译成功,也无法对其它帐号造成影响.
附加json 处理
附加包的参考:
http://blog.csdn.net/zenson_g/article/details/8491436
注:
JSONObject!=JSONArray
demo-php:
$mcrypt = new MCrypt (); // ncrypt $data = array ( 'asd' => 'as!@#!@你dfas' ); $data = json_encode ( $data ); echo $data; echo '<br>'; echo $encrypted = $mcrypt->encrypt ($data);
demo-java:
package my3des; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class tempx { public static void main(String[] arges) { MCrypt mcrypt = new MCrypt(); String encrypted; try { String decrypted = new String(mcrypt.decrypt("3a219b7b3990fc86b8d96f8d14c7a17c5800794dcd1b5f42113f7e0473a8a22e")); System.out.print(decrypted); JSONObject jsonArray = JSONObject.fromObject(decrypted); System.out.println( jsonArray ); System.out.print(jsonArray.get("asd")); } catch (Exception e) { e.printStackTrace(); } } }
转发请注明出处http://blog.martoo.cn
如有漏缺,请联系我 QQ 243008827