Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
*/
package org.apache.wicket.core.random;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import org.apache.wicket.WicketRuntimeException;

/**
* A very simple {@link ISecureRandomSupplier} that holds a {@code SecureRandom} using
* {@code SHA1PRNG}. This {@code SecureRandom} is strong enough for generation of nonces with a
* A very simple {@link ISecureRandomSupplier} that holds a {@code SecureRandom}.
* This {@code SecureRandom} is strong enough for generation of nonces with a
* short lifespan, but might not be strong enough for generating long-lived keys. When your
* application has stronger requirements on the random implementation, you should replace this class
* by your own implementation.
Expand All @@ -34,19 +31,10 @@ public class DefaultSecureRandomSupplier implements ISecureRandomSupplier
{
private static final class Holder
{
private static final SecureRandom INSTANCE;

static
{
try
{
INSTANCE = SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
throw new WicketRuntimeException(e);
}
}
private static final SecureRandom INSTANCE = new SecureRandom();
}


@Override
public SecureRandom getRandom()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import java.security.GeneralSecurityException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
import java.util.Random;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
Expand All @@ -42,6 +42,7 @@
*/
public class SunJceCrypt extends AbstractCrypt
{
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
/** Name of the default encryption method */
public static final String DEFAULT_CRYPT_METHOD = "PBEWithMD5AndDES";

Expand Down Expand Up @@ -169,7 +170,7 @@ public static byte[] randomSalt()
// must be 8 bytes - for anything else PBES1Core throws
// InvalidAlgorithmParameterException: Salt must be 8 bytes long
byte[] salt = new byte[8];
new Random().nextBytes(salt);
SECURE_RANDOM.nextBytes(salt);
return salt;
}
}