Class BcryptUtil

java.lang.Object
io.quarkus.elytron.security.common.BcryptUtil

public class BcryptUtil extends Object
Utility class used to produce bcrypt hashes using the Modular Crypt Format.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    bcryptHash(String password)
    Produces a Modular Crypt Format bcrypt hash of the given password, using a generated salt and 10 iterations.
    static String
    bcryptHash(String password, int iterationCount)
    Produces a Modular Crypt Format bcrypt hash of the given password, using a generated salt and the specified iteration count.
    static String
    bcryptHash(String password, int iterationCount, byte[] salt)
    Produces a Modular Crypt Format bcrypt hash of the given password, using the specified salt and the specified iteration count.
    static boolean
    matches(String plainText, String passwordHash)
    Matches a plain text string against an existing Modular Crypt Format bcrypt hash

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BcryptUtil

      public BcryptUtil()
  • Method Details

    • bcryptHash

      public static String bcryptHash(String password)
      Produces a Modular Crypt Format bcrypt hash of the given password, using a generated salt and 10 iterations.
      Parameters:
      password - the password to hash
      Returns:
      the Modular Crypt Format bcrypt hash of the given password
      Throws:
      NullPointerException - if the password is null
    • bcryptHash

      public static String bcryptHash(String password, int iterationCount)
      Produces a Modular Crypt Format bcrypt hash of the given password, using a generated salt and the specified iteration count.
      Parameters:
      password - the password to hash
      iterationCount - the number of iterations to use while hashing
      Returns:
      the Modular Crypt Format bcrypt hash of the given password
      Throws:
      NullPointerException - if the password is null
      IllegalArgumentException - if the iterationCount parameter is negative or zero
    • bcryptHash

      public static String bcryptHash(String password, int iterationCount, byte[] salt)
      Produces a Modular Crypt Format bcrypt hash of the given password, using the specified salt and the specified iteration count.
      Parameters:
      password - the password to hash
      iterationCount - the number of iterations to use while hashing
      salt - the salt to use while hashing
      Returns:
      the Modular Crypt Format bcrypt hash of the given password
      Throws:
      NullPointerException - if the password or salt are null
      IllegalArgumentException - if the iterationCount parameter is negative or zero, or if the salt length is not equal to 16
    • matches

      public static boolean matches(String plainText, String passwordHash)
      Matches a plain text string against an existing Modular Crypt Format bcrypt hash
      Parameters:
      plainText - the plain text string to check
      passwordHash - the Modular Crypt Format bcrypt hash to compare against
      Returns:
      the boolean result of whether the plain text matches the decoded Modular Crypt Format bcrypt hash
      Throws:
      NullPointerException - if the plainText password or passwordHash is null