File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
src/main/java/org/owasp/esapi/reference Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -54,12 +54,13 @@ public static Randomizer getInstance() {
5454 private final Logger logger = ESAPI .getLogger ("Randomizer" );
5555
5656 private DefaultRandomizer () {
57+ String algorithm = ESAPI .securityConfiguration ().getRandomAlgorithm ();
5758 try {
58- secureRandom = SecureRandom .getInstanceStrong ( );
59+ secureRandom = SecureRandom .getInstance ( algorithm );
5960 } catch (NoSuchAlgorithmException e ) {
6061 // Can't throw an exception from the constructor, but this will get
6162 // it logged and tracked
62- new EncryptionException ("Error creating randomizer" , "Failed to generate strong SecureRandom reference" , e );
63+ new EncryptionException ("Error creating randomizer" , "Can't find random algorithm " + algorithm , e );
6364 }
6465 }
6566
Original file line number Diff line number Diff line change @@ -205,7 +205,14 @@ public static void main( String[] args ) throws Exception {
205205 System .out .println ( "\t use '-print' to also show available crypto algorithms from all the security providers" );
206206 }
207207
208- SecureRandom random = SecureRandom .getInstanceStrong ();
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 );
209216 SecretKey secretKey = CryptoHelper .generateSecretKey (encryptAlgorithm , encryptionKeyLength );
210217 byte [] raw = secretKey .getEncoded ();
211218 byte [] salt = new byte [20 ]; // Or 160-bits; big enough for SHA1, but not SHA-256 or SHA-512.
@@ -273,7 +280,7 @@ private JavaEncryptor() throws EncryptionException {
273280 // For asymmetric encryption (i.e., public/private key)
274281 //
275282 try {
276- SecureRandom prng = SecureRandom .getInstanceStrong ( );
283+ SecureRandom prng = SecureRandom .getInstance ( randomAlgorithm );
277284
278285 // Because hash() is not static (but it could be were in not
279286 // for the interface method specification in Encryptor), we
You can’t perform that action at this time.
0 commit comments