下载地址http://code.google.com/p/crypto-js/


js代码


返回结果是先经过SHA1加密,然后再16进制编码


对应Java代码

public static String encode(String data, String key) {
        byte[] byteHMAC = null;
        try {
            Mac mac = Mac.getInstance("HmacSHA1");
            SecretKeySpec spec = new SecretKeySpec(key.getBytes(), "HmacSHA1");
            mac.init(spec);
            byteHMAC = mac.doFinal(data.getBytes());
        } catch (InvalidKeyException | NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        return Hex.encodeHexString(byteHMAC);
    }
System.err.println(encode("Message","d1419c25a711ed6725429a85a9ed951b"));