Class Argon2Password.Encoder
- All Implemented Interfaces:
Password.Encoder<Argon2Password,Argon2Password.Encoder>
- Enclosing class:
Argon2Password
An Argon2 password encoder implementation.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default hash length in kikibytes:32.static final intThe default iteration count:3.static final intThe default memory cost in kibibytes:12.static final intThe default parallelism:1.static final intThe default salt length in kikibytes:16.static final Argon2Password.Encoder.HashTypeThe default hash type:Argon2Password.Encoder.HashType.I. -
Constructor Summary
ConstructorsConstructorDescriptionEncoder()Creates a default Argon2 password encoder.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.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.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. -
Method Summary
Modifier and TypeMethodDescriptionEncodes the specified raw password.booleanbyte[]Returns the optional additional data.intReturns the hash length in kikibytes.intReturns the number of iterations to perform;intReturns the amount of memory to use in kibibytes.intReturns the degree of parallelism (i.e. number of threads).intReturns the salt length in kikibytes.byte[]Returns the optional secret key.Returns the secure random.getType()Returns the hash type.inthashCode()booleanMatches the specified raw password with the specified encoded representation.Recovers a password from its encoded representation generated with this encoder.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.inverno.mod.security.authentication.password.Password.Encoder
matches
-
Field Details
-
DEFAULT_TYPE
The default hash type:Argon2Password.Encoder.HashType.I. -
DEFAULT_SALT_LENGTH
public static final int DEFAULT_SALT_LENGTHThe default salt length in kikibytes:16.- See Also:
-
DEFAULT_HASH_LENGTH
public static final int DEFAULT_HASH_LENGTHThe default hash length in kikibytes:32.- See Also:
-
DEFAULT_PARALLELISM
public static final int DEFAULT_PARALLELISMThe default parallelism:1.- See Also:
-
DEFAULT_MEMORY
public static final int DEFAULT_MEMORYThe default memory cost in kibibytes:12.- See Also:
-
DEFAULT_ITERATION_COUNT
public static final int DEFAULT_ITERATION_COUNTThe default iteration count:3.- See Also:
-
-
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 typesaltLength- the salt length in kikibyteshashLength- the hash length in kikibytesparallelism- the degree of parallelismmemory- the amount of memory in kibibytesiterationCount- 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 typesaltLength- the salt length in kikibyteshashLength- the hash length in kikibytesparallelism- the degree of parallelismmemory- the amount of memory in kibibytesiterationCount- the iteration countsecret- secret dataadditionalData- 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 typesaltLength- the salt length in kikibyteshashLength- the hash length in kikibytesparallelism- the degree of parallelismmemory- the amount of memory in kikibytesiterationCount- the iteration countsecret- secret dataadditionalData- additional datasecureRandom- 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
Returns the secure random.
- Returns:
- the secure random
-
recover
Description copied from interface:Password.EncoderRecovers a password from its encoded representation generated with this encoder.
- Specified by:
recoverin interfacePassword.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
Description copied from interface:Password.EncoderEncodes the specified raw password.
- Specified by:
encodein interfacePassword.Encoder<Argon2Password,Argon2Password.Encoder> - Parameters:
raw- a raw password- Returns:
- an encoded password
- Throws:
PasswordException- if there was an error encoding the password
-
matches
Description copied from interface:Password.EncoderMatches the specified raw password with the specified encoded representation.
- Specified by:
matchesin interfacePassword.Encoder<Argon2Password,Argon2Password.Encoder> - Parameters:
raw- a raw passwordencoded- an encoded password- Returns:
- true if passwords match, false otherwise
- Throws:
PasswordException- if there was an error matching passwords
-
hashCode
public int hashCode() -
equals
-