Class Argon2Password.Encoder

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

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

An Argon2 password encoder implementation.

Since:
1.5
Author:
Jeremy Kuhn
  • Field Details

  • Constructor Details

    • Encoder

      public Encoder()

      Creates a default Argon2 password encoder.

    • Encoder

      public Encoder(Argon2Password.Encoder.HashType type, int saltLength, int hashLength, int parallelism, int memory, int iterationCount)

      Creates an Argon2 password encoder with the specified hash type, salt length, hash length, degree of parallelism, amount of memory and iteration count.

      Parameters:
      type - the hash type
      saltLength - the salt length in kikibytes
      hashLength - the hash length in kikibytes
      parallelism - the degree of parallelism
      memory - the amount of memory in kibibytes
      iterationCount - the iteration count
    • Encoder

      public Encoder(Argon2Password.Encoder.HashType type, int saltLength, int hashLength, int parallelism, int memory, int iterationCount, byte[] secret, byte[] additionalData)

      Creates an Argon2 password encoder with the specified hash type, salt length, hash length, degree of parallelism, amount of memory, iteration count, secret data and additional data.

      Parameters:
      type - the hash type
      saltLength - the salt length in kikibytes
      hashLength - the hash length in kikibytes
      parallelism - the degree of parallelism
      memory - the amount of memory in kibibytes
      iterationCount - the iteration count
      secret - secret data
      additionalData - additional data
    • Encoder

      public Encoder(Argon2Password.Encoder.HashType type, int saltLength, int hashLength, int parallelism, int memory, int iterationCount, byte[] secret, byte[] additionalData, SecureRandom secureRandom)

      Creates an Argon2 password encoder with the specified hash type, salt length, hash length, degree of parallelism, amount of memory, iteration count, secret data, additional data and secure random.

      Parameters:
      type - the hash type
      saltLength - the salt length in kikibytes
      hashLength - the hash length in kikibytes
      parallelism - the degree of parallelism
      memory - the amount of memory in kikibytes
      iterationCount - the iteration count
      secret - secret data
      additionalData - additional data
      secureRandom - a secure random
  • Method Details

    • getType

      Returns the hash type.

      Returns:
      the hash type
    • 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
    • getParallelism

      public int getParallelism()

      Returns the degree of parallelism (i.e. number of threads).

      Returns:
      the degree of parallelism
    • getMemory

      public int getMemory()

      Returns the amount of memory to use in kibibytes.

      Returns:
      the amount of memory
    • getIterationCount

      public int getIterationCount()

      Returns the number of iterations to perform;

      Returns:
      the iteration count
    • getSecret

      public byte[] getSecret()

      Returns the optional secret key.

      Returns:
      the secret key or null
    • getAdditionalData

      public byte[] getAdditionalData()

      Returns the optional additional data.

      Returns:
      the additional data or null
    • getSecureRandom

      public SecureRandom getSecureRandom()

      Returns the secure random.

      Returns:
      the secure random
    • recover

      public Argon2Password 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<Argon2Password,Argon2Password.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 Argon2Password encode(String raw) throws PasswordException
      Description copied from interface: Password.Encoder

      Encodes the specified raw password.

      Specified by:
      encode in interface Password.Encoder<Argon2Password,Argon2Password.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<Argon2Password,Argon2Password.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