Class BCrypt


  • public class BCrypt
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      BCrypt()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean checkpw​(java.lang.String plaintext, java.lang.String hashed)
      Check that a plaintext password matches a previously hashed one
      byte[] crypt_raw​(byte[] password, byte[] salt, int log_rounds, int[] cdata)
      Perform the central password hashing step in the bcrypt scheme
      static java.lang.String gensalt()
      Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable default for the number of hashing rounds to apply
      static java.lang.String gensalt​(int log_rounds)
      Generate a salt for use with the BCrypt.hashpw() method
      static java.lang.String gensalt​(int log_rounds, java.security.SecureRandom random)
      Generate a salt for use with the BCrypt.hashpw() method
      static java.lang.String hashpw​(java.lang.CharSequence password, java.lang.CharSequence salt)
      Hash a password using the OpenBSD bcrypt scheme
      static java.lang.String hashpw​(java.lang.CharSequence password, java.lang.CharSequence salt, java.io.ByteArrayOutputStream temp, java.lang.StringBuilder temp2)  
      • Methods inherited from class java.lang.Object

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

      • BCrypt

        public BCrypt()
    • Method Detail

      • hashpw

        public static java.lang.String hashpw​(java.lang.CharSequence password,
                                              java.lang.CharSequence salt)
        Hash a password using the OpenBSD bcrypt scheme
        Parameters:
        password - the password to hash
        salt - the salt to hash with (perhaps generated using BCrypt.gensalt)
        Returns:
        the hashed password
      • hashpw

        public static java.lang.String hashpw​(java.lang.CharSequence password,
                                              java.lang.CharSequence salt,
                                              java.io.ByteArrayOutputStream temp,
                                              java.lang.StringBuilder temp2)
      • gensalt

        public static java.lang.String gensalt​(int log_rounds,
                                               java.security.SecureRandom random)
        Generate a salt for use with the BCrypt.hashpw() method
        Parameters:
        log_rounds - the log2 of the number of rounds of hashing to apply - the work factor therefore increases as 2**log_rounds.
        random - an instance of SecureRandom to use
        Returns:
        an encoded salt value
      • gensalt

        public static java.lang.String gensalt​(int log_rounds)
        Generate a salt for use with the BCrypt.hashpw() method
        Parameters:
        log_rounds - the log2 of the number of rounds of hashing to apply - the work factor therefore increases as 2**log_rounds.
        Returns:
        an encoded salt value
      • gensalt

        public static java.lang.String gensalt()
        Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable default for the number of hashing rounds to apply
        Returns:
        an encoded salt value
      • checkpw

        public static boolean checkpw​(java.lang.String plaintext,
                                      java.lang.String hashed)
        Check that a plaintext password matches a previously hashed one
        Parameters:
        plaintext - the plaintext password to verify
        hashed - the previously-hashed password
        Returns:
        true if the passwords match, false otherwise
      • crypt_raw

        public byte[] crypt_raw​(byte[] password,
                                byte[] salt,
                                int log_rounds,
                                int[] cdata)
        Perform the central password hashing step in the bcrypt scheme
        Parameters:
        password - the password to hash
        salt - the binary salt to hash with the password
        log_rounds - the binary logarithm of the number of rounds of hashing to apply
        cdata - the plaintext to encrypt
        Returns:
        an array containing the binary hashed password