PiccMd5Token.java
1.23 KB
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
package com.lhcredit.common.utils;
import java.security.MessageDigest;
/**
*人保加密
*/
public class PiccMd5Token {
String Key = "55E04F01208BD9000E83DE26DB560342" ;
String SecretKey = "E8B3AB582877B1174ED37B24188DE9A3" ;
long Timespan = System.currentTimeMillis()/1000;
String token = string2MD5(Key + Timespan + SecretKey).toUpperCase();
public static String string2MD5(String inStr) {
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
return "";
}
char[] charArray = inStr.toCharArray();
byte[] byteArray = new byte[charArray.length];
for(int i = 0; i < charArray.length; ++i) {
byteArray[i] = (byte)charArray[i];
}
byte[] md5Bytes = md5.digest(byteArray);
StringBuffer hexValue = new StringBuffer();
for(int i = 0; i < md5Bytes.length; ++i) {
int val = md5Bytes[i] & 255;
if (val < 16) {
hexValue.append("0");
}
hexValue.append(Integer.toHexString(val));
}
return hexValue.toString();
}
}