package com.taover.util; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; public class UtilEncrypt { public static String MD5Lower32(String sourceStr) { String result = ""; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(sourceStr.getBytes()); byte b[] = md.digest(); int i; StringBuffer buf = new StringBuffer(""); for (int offset = 0; offset < b.length; offset++) { i = b[offset]; if (i < 0) i += 256; if (i < 16) buf.append("0"); buf.append(Integer.toHexString(i)); } result = buf.toString(); } catch (NoSuchAlgorithmException e) { System.out.println(e); } return result; } private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1"; /** * hmac sha1 * @param src * @param key * @return */ public static byte[] hmacSha1(byte[] key, byte[] src) { try { SecretKeySpec signingKey = new SecretKeySpec(key, HMAC_SHA1_ALGORITHM); Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM); mac.init(signingKey); return mac.doFinal(src); } catch (Exception e) { throw new RuntimeException(e); } } public static void main(String[] args) { System.out.println(MD5Lower32("Lexi@1799")+"6591"); System.out.println(MD5Lower32("adf8d8f44072dfae10ca8d11d060bf406591")); } }