Package anlavn.hash
Class BCrypt
java.lang.Object
anlavn.hash.BCrypt
The BCrypt class supports to OpenBSD-style Blowfish password hashing for Java.
Bcrypt is a password-hashing function designed by Niels Provos and David Mazières,
based on the Blowfish cipher and presented at USENIX in 1999.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final boolean
Use this method to check if the original string matches a previously hashed one.static final String
Use this method to encrypt the original string.static final String
genSalt()
Use this method to generate a salt for use with the BCrypt.Encrypt() method.static final String
genSalt
(int log_rounds) Use this method to generate a salt for use with the BCrypt.Encrypt() method.static final String
genSalt
(int log_rounds, SecureRandom random) Use this method to generate a salt for use with the BCrypt.Encrypt() method.
-
Constructor Details
-
BCrypt
public BCrypt()
-
-
Method Details
-
encrypt
Use this method to encrypt the original string.- Parameters:
strToEncrypt
- is the original string need encrypt.salt
- the salt to hash.- Returns:
- a BCrypt hash code of the original string.
- See Also:
-
check
Use this method to check if the original string matches a previously hashed one.- Parameters:
strToCheck
- is the original string need to check.hashedCode
- is BCrypt hash code of the original string.- Returns:
- true if the
strToCheck
matchhashCode
, false otherwise. - See Also:
-
genSalt
Use this method to generate a salt for use with the BCrypt.Encrypt() method.- Returns:
- an encoded salt value.
- See Also:
-
genSalt
Use this method to generate a salt for use with the BCrypt.Encrypt() method.- Parameters:
log_rounds
- is the Logarithm2 of the number of rounds of hashing to apply. Has a value between 4 and 30, default is 10, the larger the value, the longer the encryption time. The work factor therefore increases as 2log_rounds time.
Example:log_rounds
= 12 => 212 = 4,096 iterations.- Returns:
- an encoded salt value.
- See Also:
-
genSalt
Use this method to generate a salt for use with the BCrypt.Encrypt() method.- Parameters:
log_rounds
- is the Logarithm2 of the number of rounds of hashing to apply. Has a value between 4 and 30, default is 10, the larger the value, the longer the encryption time. The work factor therefore increases as 2log_rounds time.
Example:log_rounds
= 12 => 212 = 4,096 iterations.random
- is an instance of SecureRandom to use.- Returns:
- an encoded salt value.
- See Also:
-