如何在hmac中获得相同种子的相同输出?

4ngedf3f  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(185)

我想用同样的种子得到同样的结果。我有一个钥匙发生器:

public Key generateKey(String seed) throws NoSuchAlgorithmException {
    KeyGenerator keyGenerator = KeyGenerator.getInstance("HmacSHA512");
    keyGenerator.init(512, new SecureRandom(seed.getBytes(StandardCharsets.UTF_8)));
    return keyGenerator.generateKey();
}

这是我的mac代码:

Mac mac = Mac.getInstance("HmacSHA512");

this.mac.init(generateKey(seed));

this.buffer = ....

this.mac.update(this.buffer, 0, 8);

this.mac.doFinal(this.buffer, 0);

然而,相同的种子产生不同的结果。有什么想法吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题