开发者

SHA512 hashing with secret key

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜