How to deal with a slow SecureRandom generator?

后端 未结 17 1130
时光说笑
时光说笑 2020-11-22 11:56

If you want a cryptographically strong random numbers in Java, you use SecureRandom. Unfortunately, SecureRandom can be very slow. If it uses

17条回答
  •  春和景丽
    2020-11-22 12:18

    The problem you referenced about /dev/random is not with the SecureRandom algorithm, but with the source of randomness that it uses. The two are orthogonal. You should figure out which one of the two is slowing you down.

    Uncommon Maths page that you linked explicitly mentions that they are not addressing the source of randomness.

    You can try different JCE providers, such as BouncyCastle, to see if their implementation of SecureRandom is faster.

    A brief search also reveals Linux patches that replace the default implementation with Fortuna. I don't know much more about this, but you're welcome to investigate.

    I should also mention that while it's very dangerous to use a badly implemented SecureRandom algorithm and/or randomness source, you can roll your own JCE Provider with a custom implementation of SecureRandomSpi. You will need to go through a process with Sun to get your provider signed, but it's actually pretty straightforward; they just need you to fax them a form stating that you're aware of the US export restrictions on crypto libraries.

提交回复
热议问题