gpt4 book ai didi

java - 如何用种子生成 key ?

转载 作者:太空宇宙 更新时间:2023-11-04 13:52:12 24 4
gpt4 key购买 nike

我需要使用种子(字节数组)为我的算法生成一个 key 。此代码不起作用,因为它在不同平台上给出了 2 个不同的结果:

byte seed [] = {50,30,...};
byte result [] = new byte [20];
SecureRandom rand = new SecureRandom();
rand.setSeed(seed);
rand.nextBytes(result);

我需要在不同平台上获得相同的结果。

最佳答案

使用 SHA1PRNG 算法而不是 NativePRNG。

SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
rand.setSeed(seed);
rand.nextBytes(result);

关于java - 如何用种子生成 key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30184912/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com