【问题标题】:Using SecureRandom with SHA-256将 SecureRandom 与 SHA-256 一起使用
【发布时间】:2021-06-29 18:28:52
【问题描述】:

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

【问题讨论】:

  • 我希望 BouncyCastle 能成为一个解决方案,但他们似乎没有提供 SecureRandom 实现。您能解释一下共享随机性的更高层次的目的吗?也许我们可以设计一种不同的方法?

标签: java cryptography sha prng


【解决方案1】:

大卫,据我了解,您指的是这份文件: 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 可以生成随机数。

【讨论】:

  • 谢谢!我只是被指示迁移到 SHA256,我自己并没有真正看过该文档。我一定会把这个转给我的主管!
【解决方案2】:

我总体上同意 Victor 的声明。但作为进一步说明,NIST SP800-131a 的第 4 节有一个表格,用于分隔不使用 RBG 的 RNG,如 NIST SP800-90 或 ANSI X9.62-2005 中所述,将在 2015 年超时。

【讨论】:

    【解决方案3】:

    对 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");
    }
    

    【讨论】:

      猜你喜欢
      • 2015-03-14
      • 2020-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-19
      • 1970-01-01
      相关资源
      最近更新 更多