Skip to content

Commit eaa8ea8

Browse files
SecureRandom API Update
Replacing calls to SecureRandom.getInstance(algorithm) with SecureRandom.getInstanceStrong()
1 parent f538b35 commit eaa8ea8

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

src/main/java/org/owasp/esapi/reference/DefaultRandomizer.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ public static Randomizer getInstance() {
5454
private final Logger logger = ESAPI.getLogger("Randomizer");
5555

5656
private DefaultRandomizer() {
57-
String algorithm = ESAPI.securityConfiguration().getRandomAlgorithm();
5857
try {
59-
secureRandom = SecureRandom.getInstance(algorithm);
58+
secureRandom = SecureRandom.getInstanceStrong();
6059
} catch (NoSuchAlgorithmException e) {
6160
// Can't throw an exception from the constructor, but this will get
6261
// it logged and tracked
63-
new EncryptionException("Error creating randomizer", "Can't find random algorithm " + algorithm, e);
62+
new EncryptionException("Error creating randomizer", "Failed to generate strong SecureRandom reference", e);
6463
}
6564
}
6665

src/main/java/org/owasp/esapi/reference/crypto/JavaEncryptor.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,7 @@ public static void main( String[] args ) throws Exception {
205205
System.out.println( "\tuse '-print' to also show available crypto algorithms from all the security providers" );
206206
}
207207

208-
// setup algorithms -- Each of these have defaults if not set, although
209-
// someone could set them to something invalid. If
210-
// so a suitable exception will be thrown and displayed.
211-
encryptAlgorithm = ESAPI.securityConfiguration().getEncryptionAlgorithm();
212-
encryptionKeyLength = ESAPI.securityConfiguration().getEncryptionKeyLength();
213-
randomAlgorithm = ESAPI.securityConfiguration().getRandomAlgorithm();
214-
215-
SecureRandom random = SecureRandom.getInstance(randomAlgorithm);
208+
SecureRandom random = SecureRandom.getInstanceStrong();
216209
SecretKey secretKey = CryptoHelper.generateSecretKey(encryptAlgorithm, encryptionKeyLength);
217210
byte[] raw = secretKey.getEncoded();
218211
byte[] salt = new byte[20]; // Or 160-bits; big enough for SHA1, but not SHA-256 or SHA-512.
@@ -280,7 +273,7 @@ private JavaEncryptor() throws EncryptionException {
280273
// For asymmetric encryption (i.e., public/private key)
281274
//
282275
try {
283-
SecureRandom prng = SecureRandom.getInstance(randomAlgorithm);
276+
SecureRandom prng = SecureRandom.getInstanceStrong();
284277

285278
// Because hash() is not static (but it could be were in not
286279
// for the interface method specification in Encryptor), we

0 commit comments

Comments
 (0)