我需要编写一个随机数生成器,该生成器使用符合 FIPS 140-2 标准/认证的算法。我很难找到任何对我有用的东西。以前有人做过这个吗?我不想为此付出一臂之力。
使用Java 8,开发环境为Mac OSX,服务器为CentOs 7。
更新:
到目前为止,代码看起来像这样。
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
public class LongRandom {
public LongRandom(){}
private Long minLong = new Long("1000000000000000000");
public List<Long> getRandomLongList(int numberOfRandom){
final SecureRandom random = new SecureRandom();
LongStream longs = random.longs(numberOfRandom, minLong, Long.MAX_VALUE).distinct();
long[] arrayLong = longs.toArray();
List<Long> list = Arrays.stream(arrayLong).boxed().collect(Collectors.toList());
return list;
}
public Long getRandomLongWinner(List<Long> potentialWinners){
final SecureRandom random = new SecureRandom();
Collections.shuffle(potentialWinners,random);
IntStream ints = random.ints(1,0,(potentialWinners.size() - 1));
return potentialWinners.get(ints.findFirst().getAsInt());
}
}
最佳答案
这是适当 RNG 的官方列表。 BSAFE 被广泛使用。
http://csrc.nist.gov/groups/STM/cavp/documents/rng/rngval.html
关于java - 符合 FIPS 140-2 的随机数生成器 - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42566808/