Home > Backend Development > PHP Tutorial > java转php加密和好密

java转php加密和好密

WBOY
Release: 2016-06-13 12:38:16
Original
981 people have browsed it

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


<br>
package com.test.moltest;<br>
<br>
import java.util.Collection;<br>
import java.util.Iterator;<br>
<br>
import net.sf.json.JSONArray;<br>
import net.sf.json.JSONObject;<br>
<br>
import org.apache.commons.logging.Log;<br>
import org.apache.commons.logging.LogFactory;<br>
<br>
import com.capinfo.crypt.Md5;<br>
<br>
/**<br>
 * Created by IntelliJ IDEA.<br>
 * User: bob_0703<br>
 * Date: 2008-10-18<br>
 * Time: 17:30:53<br>
 * To change this template use File | Settings | File Templates.<br>
 */<br>
public class UserJsonUtil {<br>
<br>
    private static final Log log = LogFactory.getLog("UserJsonUtil.class");<br>
<br>
    public static boolean decryptJsonUser(String s) {<br>
        boolean rs = false;<br>
        try {<br>
            s = DESTools.decrypt("testtest", s);//解密1<br>
<br>
            JSONObject jobj = JSONObject.fromObject(s);//转换成为json<br>
            JSONArray names=jobj.names();<br>
            String md5Str = (String) jobj.get("md5");//获取加密后的MD5<br>
<br>
            names.remove(names.size()-1);<br>
            StringBuffer buf=new StringBuffer();<br>
            Iterator<string> it=names.iterator();<br>
            while(it.hasNext()){<br>
                String name=it.next();<br>
                buf.append(jobj.get(name));<br>
            }<br>
<br>
            jobj.remove("md5");<br>
            Md5 md5 = new Md5("");<br>
            md5.hmac_Md5(buf.toString(), "test");<br>
            byte b[] = md5.getDigest(); <div class="clear">
                 
              
              
        
            </div></string>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template