Class BCrypt


  • public final class BCrypt
    extends java.lang.Object
    Core of password hashing scheme Bcrypt, designed by Niels Provos and David Mazières, corresponds to the C reference implementation.

    This implementation does not correspondent to the 1999 published paper "A Future-Adaptable Password Scheme" of Niels Provos and David Mazières, see: https://www.usenix.org/legacy/events/usenix99/provos/provos_html/node1.html. In contrast to the paper, the order of key setup and salt setup is reversed: state <- ExpandKey(state, 0, key) state <- ExpandKey(state, 0, salt) This corresponds to the OpenBSD reference implementation of Bcrypt.

    Note: There is no successful cryptanalysis (status 2015), but the amount of memory and the band width of Bcrypt may be insufficient to effectively prevent attacks with custom hardware like FPGAs, ASICs

    This implementation uses some parts of Bouncy Castle's BlowfishEngine.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] generate​(byte[] pwInput, byte[] salt, int cost)
      Calculates the bcrypt hash of an input - note for processing general passwords you want to make sure the password is terminated in a manner similar to what is done by passwordToByteArray().
      static byte[] passwordToByteArray​(char[] password)
      Converts a character password to bytes incorporating the required trailing zero byte.
      • Methods inherited from class java.lang.Object

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

      • passwordToByteArray

        public static byte[] passwordToByteArray​(char[] password)
        Converts a character password to bytes incorporating the required trailing zero byte.
        Parameters:
        password - the password to be encoded.
        Returns:
        a byte representation of the password in UTF8 + trailing zero.
      • generate

        public static byte[] generate​(byte[] pwInput,
                                      byte[] salt,
                                      int cost)
        Calculates the bcrypt hash of an input - note for processing general passwords you want to make sure the password is terminated in a manner similar to what is done by passwordToByteArray().

        This implements the raw bcrypt function as defined in the bcrypt specification, not the crypt encoded version implemented in OpenBSD.

        Parameters:
        pwInput - the password bytes (up to 72 bytes) to use for this invocation.
        salt - the 128 bit salt to use for this invocation.
        cost - the bcrypt cost parameter. The cost of the bcrypt function grows as 2^cost. Legal values are 4..31 inclusive.
        Returns:
        the output of the raw bcrypt operation: a 192 bit (24 byte) hash.