Class Argon2Hash

java.lang.Object
br.net.dd.netherwingcore.common.cryptography.Argon2Hash

public final class Argon2Hash extends Object
Utility class for hashing and verifying passwords using the Argon2 algorithm.
  • Field Details

  • Method Details

    • hash

      public static Optional<String> hash(String password, byte[] saltBytes)
      Hashes a password using the Argon2 algorithm with the provided salt and default parameters.
      Parameters:
      password - The password to hash.
      saltBytes - The salt to use for hashing.
      Returns:
      An Optional containing the encoded hash if successful, or an empty Optional if an error occurs.
    • hash

      public static Optional<String> hash(String password, byte[] saltBytes, int nIterations, int kibMemoryCost)
      Hashes a password using the Argon2 algorithm with the provided parameters.
      Parameters:
      password - The password to hash.
      saltBytes - The salt to use for hashing.
      nIterations - The number of iterations to perform.
      kibMemoryCost - The memory cost in KiB.
      Returns:
      An Optional containing the encoded hash if successful, or an empty Optional if an error occurs.
    • verify

      public static boolean verify(String password, String encodedHash)
      Verifies a password against an encoded hash.
      Parameters:
      password - The password to verify.
      encodedHash - The encoded hash to compare against.
      Returns:
      True if the password matches the hash, false otherwise.