java轉php加密和好密

來源:互聯網
上載者:User
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();
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.