Record Class Argon2PhcString

java.lang.Object
java.lang.Record
io.micronaut.security.password.argon2.Argon2PhcString
Record Components:
memory - the memory cost, in kibibytes
iterations - the number of iterations
parallelism - the degree of parallelism
salt - the salt
hash - the hash

@Internal public record Argon2PhcString(long memory, long iterations, int parallelism, byte[] salt, byte[] hash) extends Record
An Argon2id hash in the PHC string format: $argon2id$v=19$m=<memory>,t=<iterations>,p=<parallelism>$<salt>$<hash>.

Parsing is strict. Only Argon2id version 19 is accepted, the parameters must appear in the order m,t,p as decimals without leading zeros, and the salt and hash must be canonical unpadded Base64. The optional keyid and data parameters are not supported.

Since:
5.5.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Longest hash, in bytes, allowed by the PHC string format.
    static final int
    Highest degree of parallelism allowed by the PHC string format.
    static final int
    Longest salt, in bytes, allowed by the PHC string format.
    static final int
    Lowest memory cost, in kibibytes, that Argon2 accepts for each degree of parallelism.
    static final int
    Shortest hash, in bytes, allowed by the PHC string format.
    static final int
    Shortest salt, in bytes, allowed by the PHC string format.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Argon2PhcString(long memory, long iterations, int parallelism, byte[] salt, byte[] hash)
    Creates an instance of a Argon2PhcString record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    static String
    format(int memory, int iterations, int parallelism, byte[] salt, byte[] hash)
    Formats an Argon2id hash as a PHC string.
    byte[]
    Returns the value of the hash record component.
    final int
    Returns a hash code value for this object.
    long
    Returns the value of the iterations record component.
    long
    Returns the value of the memory record component.
    int
    Returns the value of the parallelism record component.
    static @Nullable Argon2PhcString
    parse(String encoded)
    Parses an Argon2id PHC string.
    byte[]
    Returns the value of the salt record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • MEMORY_PER_LANE

      public static final int MEMORY_PER_LANE
      Lowest memory cost, in kibibytes, that Argon2 accepts for each degree of parallelism.
      See Also:
    • MAX_PARALLELISM

      public static final int MAX_PARALLELISM
      Highest degree of parallelism allowed by the PHC string format.
      See Also:
    • MIN_SALT_LENGTH

      public static final int MIN_SALT_LENGTH
      Shortest salt, in bytes, allowed by the PHC string format.
      See Also:
    • MAX_SALT_LENGTH

      public static final int MAX_SALT_LENGTH
      Longest salt, in bytes, allowed by the PHC string format.
      See Also:
    • MIN_HASH_LENGTH

      public static final int MIN_HASH_LENGTH
      Shortest hash, in bytes, allowed by the PHC string format.
      See Also:
    • MAX_HASH_LENGTH

      public static final int MAX_HASH_LENGTH
      Longest hash, in bytes, allowed by the PHC string format.
      See Also:
  • Constructor Details

    • Argon2PhcString

      public Argon2PhcString(long memory, long iterations, int parallelism, byte[] salt, byte[] hash)
      Creates an instance of a Argon2PhcString record class.
      Parameters:
      memory - the value for the memory record component
      iterations - the value for the iterations record component
      parallelism - the value for the parallelism record component
      salt - the value for the salt record component
      hash - the value for the hash record component
  • Method Details

    • parse

      public static @Nullable Argon2PhcString parse(String encoded)
      Parses an Argon2id PHC string.
      Parameters:
      encoded - the PHC string
      Returns:
      the parsed string, or null if it is not a conforming Argon2id PHC string
    • format

      public static String format(int memory, int iterations, int parallelism, byte[] salt, byte[] hash)
      Formats an Argon2id hash as a PHC string.
      Parameters:
      memory - the memory cost, in kibibytes
      iterations - the number of iterations
      parallelism - the degree of parallelism
      salt - the salt
      hash - the hash
      Returns:
      the PHC string
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • memory

      public long memory()
      Returns the value of the memory record component.
      Returns:
      the value of the memory record component
    • iterations

      public long iterations()
      Returns the value of the iterations record component.
      Returns:
      the value of the iterations record component
    • parallelism

      public int parallelism()
      Returns the value of the parallelism record component.
      Returns:
      the value of the parallelism record component
    • salt

      public byte[] salt()
      Returns the value of the salt record component.
      Returns:
      the value of the salt record component
    • hash

      public byte[] hash()
      Returns the value of the hash record component.
      Returns:
      the value of the hash record component