Class PBKDF2Password.Encoder

java.lang.Object
io.inverno.mod.security.authentication.password.PBKDF2Password.Encoder
All Implemented Interfaces:
Password.Encoder<PBKDF2Password,PBKDF2Password.Encoder>
Enclosing class:
PBKDF2Password

public static class PBKDF2Password.Encoder extends Object implements Password.Encoder<PBKDF2Password,PBKDF2Password.Encoder>

A PBKDF2 based password encoder implementation.

Since:
1.5
Author:
Jeremy Kuhn
  • Field Details

    • PRF_SHA256

      public static final String PRF_SHA256
      SHA256 pseudorandom function.
      See Also:
    • PRF_SHA384

      public static final String PRF_SHA384
      SHA384 pseudorandom function.
      See Also:
    • PRF_SHA512

      public static final String PRF_SHA512
      SHA512 pseudorandom function.
      See Also:
    • DEFAULT_PRF

      public static final String DEFAULT_PRF
      Default pseudorandom function.
      See Also:
    • DEFAULT_SALT_LENGTH

      public static final int DEFAULT_SALT_LENGTH
      Default salt length in kikibytes: 16.
      See Also:
    • DEFAULT_HASH_LENGTH

      public static final int DEFAULT_HASH_LENGTH
      Default hash length in kikibytes: 32.
      See Also:
    • DEFAULT_ITERATION_COUNT

      public static final int DEFAULT_ITERATION_COUNT
      Default iteration count: 1000.
      See Also:
  • Constructor Details

    • Encoder

      public Encoder()

      Creates a default PBKDF2 password encoder.

    • Encoder

      public Encoder(String prf)

      Creates a PBKDF2 password encoder with the specified pseudorandom function.

      Parameters:
      prf - the pseudorandom function
    • Encoder

      public Encoder(String prf, int iterationCount, int saltLength, int hashLength)

      Creates a PBKDF2 password encoder with the specified pseudorandom function, iteration count, salt length and hash length.

      Parameters:
      prf - the pseudorandom function
      iterationCount - the iteration count
      saltLength - the salt length in kikibytes
      hashLength - the hash length in kikibytes
    • Encoder

      public Encoder(String prf, int iterationCount, int saltLength, int hashLength, SecureRandom secureRandom)

      Creates a PBKDF2 password encoder with the specified pseudorandom function, iteration count, salt length, hash length and secure random.

      Parameters:
      prf - the pseudorandom function
      iterationCount - the iteration count
      saltLength - the salt length in kikibytes
      hashLength - the hash length in kikibytes
      secureRandom - the secure random
  • Method Details

    • getPseudoRandomFunction

      public String getPseudoRandomFunction()

      Returns the pseudorandom function.

      Returns:
      the pseudorandom function
    • getIterationCount

      public int getIterationCount()

      Returns the iteration count.

      Returns:
      the iteration count
    • getSaltLength

      public int getSaltLength()

      Returns the salt length in kikibytes.

      Returns:
      the salt length
    • getHashLength

      public int getHashLength()

      Returns the hash length in kikibytes.

      Returns:
      the hash length
    • getSecureRandom

      public SecureRandom getSecureRandom()

      Returns the secure random.

      Returns:
      the secure random
    • recover

      public PBKDF2Password recover(String encoded) throws PasswordException
      Description copied from interface: Password.Encoder

      Recovers a password from its encoded representation generated with this encoder.

      Specified by:
      recover in interface Password.Encoder<PBKDF2Password,PBKDF2Password.Encoder>
      Parameters:
      encoded - an encoded password representation
      Returns:
      a password
      Throws:
      PasswordException - if there was an error recovering the password or if the specified encoded representation was not generated with this encoder
    • encode

      public PBKDF2Password encode(String raw) throws PasswordException
      Description copied from interface: Password.Encoder

      Encodes the specified raw password.

      Specified by:
      encode in interface Password.Encoder<PBKDF2Password,PBKDF2Password.Encoder>
      Parameters:
      raw - a raw password
      Returns:
      an encoded password
      Throws:
      PasswordException - if there was an error encoding the password
    • matches

      public boolean matches(String raw, String encoded) throws PasswordException
      Description copied from interface: Password.Encoder

      Matches the specified raw password with the specified encoded representation.

      Specified by:
      matches in interface Password.Encoder<PBKDF2Password,PBKDF2Password.Encoder>
      Parameters:
      raw - a raw password
      encoded - an encoded password
      Returns:
      true if passwords match, false otherwise
      Throws:
      PasswordException - if there was an error matching passwords
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object