当前位置:Gxlcms > PHP教程 > java转php加密和好密

java转php加密和好密

时间:2021-07-01 10:21:17 帮助过:16人阅读

java转php加密和解密
将UserJsonUtil类中的
encryptJsonUser()加密,写成php的加密;
decryptJsonUser()解密,写成php的解密。



package com.test.moltest;

import java.util.Collection;
import java.util.Iterator;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.capinfo.crypt.Md5;

/**
* Created by IntelliJ IDEA.
* User: bob_0703
* Date: 2008-10-18
* Time: 17:30:53
* To change this template use File | Settings | File Templates.
*/
public class UserJsonUtil {

private static final Log log = LogFactory.getLog("UserJsonUtil.class");

public static boolean decryptJsonUser(String s) {
boolean rs = false;
try {
s = DESTools.decrypt("testtest", s);//解密1

JSONObject jobj = JSONObject.fromObject(s);//转换成为json
JSONArray names=jobj.names();
String md5Str = (String) jobj.get("md5");//获取加密后的MD5

names.remove(names.size()-1);
StringBuffer buf=new StringBuffer();
Iterator it=names.iterator();
while(it.hasNext()){
String name=it.next();
buf.append(jobj.get(name));
}

jobj.remove("md5");
Md5 md5 = new Md5("");
md5.hmac_Md5(buf.toString(), "test");
byte b[] = md5.getDigest();

人气教程排行