### Question:
BCrypt { public static Hasher withDefaults() { return new Hasher(Version.VERSION_2A, new SecureRandom(), LongPasswordStrategies.strict(Version.VERSION_2A)); } private  BCrypt(); static Hasher withDefaults(); static Hasher with(Version version); static Hasher with(SecureRandom secureRandom); static Hasher with(LongPasswordStrategy longPasswordStrategy); static Hasher with(Version version, LongPasswordStrategy longPasswordStrategy); static Hasher with(Version version, SecureRandom secureRandom, LongPasswordStrategy longPasswordStrategy); static Verifyer verifyer(); static Verifyer verifyer(Version version); static Verifyer verifyer(Version version, LongPasswordStrategy longPasswordStrategy); static final int SALT_LENGTH; static final int MIN_COST; static final int MAX_COST; }### Answer:
@Test public void testSimpleBcryptHashes() { byte[] salt = new byte[]{0x5E, (byte) 0xFA, (byte) 0xA7, (byte) 0xA3, (byte) 0xD9, (byte) 0xDF, 0x6E, (byte) 0x7F, (byte) 0x8C, 0x78, (byte) 0x96, (byte) 0xB1, 0x7B, (byte) 0xA7, 0x6E, 0x01}; BCrypt.Hasher bCrypt = BCrypt.withDefaults(); for (int i = 4; i < 10; i++) { byte[] hash = bCrypt.hash(i, salt, "abcdefghijkl1234567öäü-,:".getBytes()); assertEquals(60, hash.length); System.out.println(Bytes.wrap(hash).encodeUtf8()); } }
@Test(expected = IllegalArgumentException.class) public void createHashWithPwNull() { BCrypt.withDefaults().hash(6, new byte[16], null); }
@Test(expected = IllegalArgumentException.class) public void createHashWithCharPwNull() { BCrypt.withDefaults().hash(6, (char[]) null); }
@Test(expected = IllegalArgumentException.class) public void createHashWithPwTooLong() { BCrypt.withDefaults().hash(6, new byte[16], new byte[DEFAULT_VERSION.allowedMaxPwLength + 1]); }
@Test(expected = IllegalArgumentException.class) public void createHashWithPwTooLong2() { BCrypt.withDefaults().hash(6, new byte[16], new byte[DEFAULT_VERSION.allowedMaxPwLength + 2]); }
@Test public void testWithNullTerminatorWithinPw_shouldNotTerminate() { byte[] pw1 = Bytes.from("secret").append(0x00).append("butthereismore").array(); byte[] pw2 = Bytes.from("secret").array(); byte[] salt = Bytes.random(16).array(); String hash1 = Bytes.wrap(BCrypt.withDefaults().hash(4, salt, pw1)).toString(); String hash2 = Bytes.wrap(BCrypt.withDefaults().hash(4, salt, pw2)).toString(); assertNotEquals(hash1, hash2); System.out.println(hash1 + "\n" + hash2); }
@Test(expected = IllegalArgumentException.class) public void createHashCostTooSmall() { BCrypt.withDefaults().hash(3, "123".toCharArray()); }
@Test(expected = IllegalArgumentException.class) public void createHashCostTooBig() { BCrypt.withDefaults().hash(32, "123".toCharArray()); }
@Test(expected = IllegalArgumentException.class) public void createHashWithNullSalt() { BCrypt.withDefaults().hash(6, null, "123".getBytes()); }
@Test(expected = IllegalArgumentException.class) public void createHashWithSaltTooShort() { BCrypt.withDefaults().hash(6, new byte[15], "123".getBytes()); }
@Test(expected = IllegalArgumentException.class) public void createHashWithSaltTooLong() { BCrypt.withDefaults().hash(6, new byte[17], "123".getBytes()); }