java equivalent to php's hmac-SHA1

前端 未结 7 938
花落未央
花落未央 2020-11-28 20:33

I\'m looking for a java equivalent to this php call:

hash_hmac(\'sha1\', \"test\", \"secret\")

I tried this, using java.crypto.Mac, but the

7条回答
  •  伪装坚强ぢ
    2020-11-28 21:19

    Haven't tested it, but try this:

            BigInteger hash = new BigInteger(1, digest);
            String enc = hash.toString(16);
            if ((enc.length() % 2) != 0) {
                enc = "0" + enc;
            }
    

    This is snapshot from my method that makes java's md5 and sha1 match php.

提交回复
热议问题