将SecureRandom与SHA-256一起使用

时间:2012-10-04 16:04:09

标签: java cryptography sha prng

我一直在使用带有种子SHA1PRNG算法的SecureRandom来创建两个进程之间的共享随机性。我最近了解到SHA1根据NIST的标准被弃用,所以我们正在努力切换到SHA256。我发现的问题是SecureRandom仅支持SHA1PRNG,至少根据Oracle's documentation。我想知道是否有办法将SecureRandom与SHA256一起使用,或者可能更好,什么是使用SecureRandom的合适替代方案?

3 个答案:

答案 0 :(得分:15)

大卫,据我了解你指的是这份文件: http://csrc.nist.gov/publications/nistpubs/800-131A/sp800-131A.pdf

可能是,我错过了什么。但是,它说:

From January 1, 2011 through December 31, 2013, the use of SHA-1 is deprecated 
for digital signature generation. The user must accept risk when SHA-1 is used, 
particularly when approaching the December 31, 2013 upper limit.

然而,在它下面说

For all other hash function applications, the use of SHA-1 is acceptable. The 
other applications include HMAC, Key Derivation Functions (KDFs), Random Number 
Generation (RNGs and RBGs), and hash-only applications (e.g., hashing passwords 
and using SHA-1 to compute a checksum, such as the approved integrity technique 
specified in Section 4.6.1 of [FIPS 140-2]). 

所以,据我所知,SHA1可以生成随机数。

答案 1 :(得分:3)

我同意维克多的声明。但作为进一步的澄清,NIST SP800-131a的第4部分有一个表格,用于分隔不使用RBG的RNG,如NIST SP800-90或ANSI X9.62-2005中提到的将在2015年超时。

答案 2 :(得分:0)

对 Android (Java) 使用以下代码:

SecureRandom random = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
   random = SecureRandom.getInstanceStrong();
} else {
   random = SecureRandom.getInstance("NativePRNG");
}