Commit d070efd9 by Li Yongyu

md5 算法优化

parent 702705cd
......@@ -6,7 +6,7 @@
<classes>
<class name="com.puhui.test.RenMai_APITest">
<methods>
<include name="f" invocation-numbers="0 1 2 3 4 5 6 7 8 "/>
<include name="f" invocation-numbers="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 "/>
</methods>
</class>
</classes>
......
package com.offcn.api.nwn.md5;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class LMFMD5 {
//����һ����LMFMD5
public static String MD5(String sourceStr) {
public static String MD5(String str) {
/*
String result = "";
try {
MessageDigest md = MessageDigest.getInstance("MD5");
......@@ -31,7 +34,37 @@ public class LMFMD5 {
} catch (NoSuchAlgorithmException e) {
System.out.println(e);
}
return result;
return result;*/
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("MD5");
messageDigest.reset();
messageDigest.update(str.getBytes("UTF-8"));
} catch (NoSuchAlgorithmException e) { // NOSONAR
System.out.println(e.getMessage());
} catch (UnsupportedEncodingException e) { // NOSONAR
System.out.println(e.getMessage());
}
byte[] byteArray = messageDigest.digest();
StringBuffer md5StrBuff = new StringBuffer();
for (int i = 0; i < byteArray.length; i++) {
if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
else
md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
}
// return md5StrBuff.toString().toUpperCase();
return md5StrBuff.toString();
}
}
package com.offcn.api.nwn.md5;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import com.offcn.process.NWN;
public class nwngetsign {
......@@ -30,10 +33,11 @@ public class nwngetsign {
str = str + "bf2h3%^j?ljkj3706kji88697"; //教务的加密,规则固定需要加
System.out.println("str===" + str);
//String str1 = "appid=tiku&avatar=http://thirdqq.qlogo.cn/qqapp/1106773681/5B50BBF83A00DC46B16B708F720A5D46/100&device_id=861837034477409&login_type=qq&nickname=hobo&open_id=1&platform=Android&version=1"+"&123456";
String res = new LMFMD5().MD5(str);
System.out.println("res===" +res);
return res;
......
......@@ -29,7 +29,7 @@ import net.sf.json.JSONObject;
/**
* 添加母版层级
* 删除班级(教务包)
*
* @author liyy
*
......
......@@ -29,7 +29,7 @@ import net.sf.json.JSONObject;
/**
* 添加母版层级
* 查找母版下是否有对应的教务包
*
* @author liyy
*
......
......@@ -113,7 +113,7 @@ public class APITest_nwn extends NWN{
//数据回写
// HashMap<String, Object> ExpectResult=MapUtil.Expect(data);
/* SheetUtils sheet = new SheetUtils("DataAll.xls", "Output");
/* SheetUtils sheet = new SheetUtils("DataAll.xls", "Output");
sheet.writeExcel(
data.get("NO").toString(),
data.get("TCNO").toString() + "_Step" + data.get("Step").toString(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment