4

Given SecureRandom class is considered suitable for use in cryptography, I consider new SecureRandom() to be secure (funny term, isn't it?).

If new SecureRandom() already is secure, what would be the benefit of using SecureRandom.getInstanceStrong() instead?

Is this same kind of difference as between /dev/urandom and /dev/random?

I'm debating this in the following scenario, where I'm mostly concerned about making IV random (for use with AES-GCM):

private final SecureRandom secureRandom = new SecureRandom();

[...]

private byte[] getIv() { int ivLength = 12; byte[] iv = new byte[ivLength]; secureRandom.nextBytes(iv); return iv; }

1 Answers1

2

SecureRandom.getInstanceStrong() will ensure that a strong algorithm (securerandom.strongAlgorithms) will is used.

  • It is available since Java version 8. Check your version before starting to use.

  • If no such algorithm is available in running VM, it will throw NoSuchAlgorithmException.

  • This failure is a better practice instead of defaulting into weak security.

kelalaka
  • 48,443
  • 11
  • 116
  • 196
  • 1
    Welcome to Cryptography. A link to this claim or code line from the source will make this answer much better. Otherwise, this is a self claim. For example one could also say, it there is no strong ( what is the meaning of strong) algorithm then it will use the default one; java.util.Random. There is need for reference and in Java case, even versions.. – kelalaka Dec 27 '21 at 21:51
  • Thank your for your feedback kelalaka, I've added a bit more clarifications, as you suggested. – cactusresistance Dec 27 '21 at 23:56
  • Is there a list of strongAlgorithms? – kelalaka Dec 28 '21 at 06:33
  • @kelalaka 'Strong' is a common term used by cryptographers, agencies and totalitarian governments to label an encryption can can't be defeated in real time. There's a list here. I don't know if AES should be added as there is no mathematical evidence that it's still secure. – Paul Uszak Dec 28 '21 at 16:48
  • @PaulUszak I'm talking about in the context of the Java Security and specially on the random number generatos. – kelalaka Dec 28 '21 at 16:58