我一直在使用带有种子的SHA1PRNG算法的SecureRandom来创建两个进程之间的共享随机数。最近我了解到,根据NIST的标准,SHA1已经被弃用,因此我们正在努力切换到SHA256。我发现的问题是SecureRandom仅支持SHA1PRNG,至少根据Oracle文档。我想知道是否有一种方法可以使用SecureRandom和SHA256,或者更好的选择是什么替代SecureRandom?
我一直在使用带有种子的SHA1PRNG算法的SecureRandom来创建两个进程之间的共享随机数。最近我了解到,根据NIST的标准,SHA1已经被弃用,因此我们正在努力切换到SHA256。我发现的问题是SecureRandom仅支持SHA1PRNG,至少根据Oracle文档。我想知道是否有一种方法可以使用SecureRandom和SHA256,或者更好的选择是什么替代SecureRandom?
David,我理解你指的是这个文档: 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对于随机数生成是可以的。
我总体上同意Victor的说法。但需要进一步澄清的是,NIST SP800-131a的第4节有一个表格,将不使用RBGs(如NIST SP800-90或ANSI X9.62-2005中所述)的RNG在2015年后会超时。
在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");
}