PiccMd5Token.java 1.23 KB
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();
    }
}