开发者

SHA512 hashing with secret key

开发者 https://www.devze.com 2023-04-12 04:13 出处:网络
What is the Java equivalent of http://php.net/manual/en/function.hash-hmac.php ? I need开发者_开发问答 to specify both the data and the secret key to generate a SHA512 hash.

What is the Java equivalent of http://php.net/manual/en/function.hash-hmac.php ?

I need开发者_开发问答 to specify both the data and the secret key to generate a SHA512 hash.

Best I've found so far is http://commons.apache.org/codec/apidocs/org/apache/commons/codec/digest/DigestUtils.html#sha512Hex(java.lang.String) but how do I specify the key?


Bouncy Castle includes an HMAC class which can use any digest (=hash) available, including SHA-256.


I recommend using Apache Commons Codec and especially its DigestUtils.

For instance like this:

public String calcSha(String secret, String data) {
    return DigestUtils.sha512Hex(secret + data);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号