/** * Create a {@link BytesKeyGenerator} that returns a single, shared * {@link SecureRandom} key of a custom length. * @param keyLength the key length in bytes, e.g. 16, for a 16 byte key. */ public static BytesKeyGenerator shared(int keyLength) { return new SharedKeyGenerator(secureRandom(keyLength).generateKey()); }
/** * Creates a {@link StringKeyGenerator} that hex-encodes {@link SecureRandom} keys of * 8 bytes in length. The hex-encoded string is keyLength * 2 characters in length. */ public static StringKeyGenerator string() { return new HexEncodingStringKeyGenerator(secureRandom()); }
/** * Create a {@link BytesKeyGenerator} that uses a {@link SecureRandom} to generate * keys of a custom length. * @param keyLength the key length in bytes, e.g. 16, for a 16 byte key. */ public static BytesKeyGenerator secureRandom(int keyLength) { return new SecureRandomBytesKeyGenerator(keyLength); }
private byte[] iv(byte[] encrypted) { return this.ivGenerator != NULL_IV_GENERATOR ? subArray(encrypted, 0, this.ivGenerator.getKeyLength()) : NULL_IV_GENERATOR.generateKey(); }
protected AbstractPasswordEncoder() { this.saltGenerator = KeyGenerators.secureRandom(); }
/** * Encodes the rawPass using a MessageDigest. If a salt is specified it will be merged * with the password before encoding. * * @param rawPassword The plain text password * @return Hex string of password digest (or base64 encoded string if * encodeHashAsBase64 is enabled. */ public String encode(CharSequence rawPassword) { String salt = PREFIX + this.saltGenerator.generateKey() + SUFFIX; return digest(salt, rawPassword); }
@Override public String encode(CharSequence rawPassword) { byte[] salt = this.saltGenerator.generateKey(); byte[] encoded = encode(rawPassword, salt); return encode(encoded); }
@Test(expected = IllegalArgumentException.class) public void constructorEncoderWhenEncoderNullThenThrowsIllegalArgumentException() { Base64.Encoder encoder = null; new Base64StringKeyGenerator(null); }
/** * Create a {@link BytesKeyGenerator} that returns a single, shared * {@link SecureRandom} key of a custom length. * @param keyLength the key length in bytes, e.g. 16, for a 16 byte key. */ public static BytesKeyGenerator shared(int keyLength) { return new SharedKeyGenerator(secureRandom(keyLength).generateKey()); }
BouncyCastleAesBytesEncryptor(String password, CharSequence salt) { this(password, salt, KeyGenerators.secureRandom(16)); }
/** * Creates a {@link StringKeyGenerator} that hex-encodes {@link SecureRandom} keys of * 8 bytes in length. The hex-encoded string is keyLength * 2 characters in length. */ public static StringKeyGenerator string() { return new HexEncodingStringKeyGenerator(secureRandom()); }
/** * Encodes the rawPass using a MessageDigest. If a salt is specified it will be merged * with the password before encoding. * * @param rawPassword The plain text password * @return Hex string of password digest (or base64 encoded string if * encodeHashAsBase64 is enabled. */ public String encode(CharSequence rawPassword) { String salt = PREFIX + this.saltGenerator.generateKey() + SUFFIX; return digest(salt, rawPassword); }
/** * Create a {@link BytesKeyGenerator} that uses a {@link SecureRandom} to generate * keys of 8 bytes in length. */ public static BytesKeyGenerator secureRandom() { return new SecureRandomBytesKeyGenerator(); }
@Test(expected = IllegalArgumentException.class) public void constructorIntWhenLessThan32ThenIllegalArgumentException() { new Base64StringKeyGenerator(31); }
public LdapShaPasswordEncoder() { this(KeyGenerators.secureRandom()); }
/** * Create a {@link BytesKeyGenerator} that uses a {@link SecureRandom} to generate * keys of a custom length. * @param keyLength the key length in bytes, e.g. 16, for a 16 byte key. */ public static BytesKeyGenerator secureRandom(int keyLength) { return new SecureRandomBytesKeyGenerator(keyLength); }
BouncyCastleAesBytesEncryptor(String password, CharSequence salt) { this(password, salt, KeyGenerators.secureRandom(16)); }
/** * Create a {@link BytesKeyGenerator} that uses a {@link SecureRandom} to generate * keys of 8 bytes in length. */ public static BytesKeyGenerator secureRandom() { return new SecureRandomBytesKeyGenerator(); }
public LdapShaPasswordEncoder() { this(KeyGenerators.secureRandom()); }
protected AbstractPasswordEncoder() { this.saltGenerator = KeyGenerators.secureRandom(); }