public class BCrypt extends Object
String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt());
To check whether a plaintext password matches one that has been
hashed previously, use the checkpw method:
if (BCrypt.checkpw(candidate_password, stored_hash))
System.out.println("It matches");
else
System.out.println("It does not match");
The gensalt() method takes an optional parameter (log_rounds)
that determines the computational complexity of the hashing:
String strong_salt = BCrypt.gensalt(10)
String stronger_salt = BCrypt.gensalt(12)
The amount of work increases exponentially (2**log_rounds), so
each increment is twice as much work. The default log_rounds is
10, and the valid range is 4 to 30.| Constructor and Description |
|---|
BCrypt() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
checkpw(String plaintext,
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 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 String |
gensalt(int log_rounds)
Generate a salt for use with the BCrypt.hashpw() method
|
static String |
gensalt(int log_rounds,
SecureRandom random)
Generate a salt for use with the BCrypt.hashpw() method
|
static String |
hashpw(String password,
String salt)
Hash a password using the OpenBSD bcrypt scheme
|
public byte[] crypt_raw(byte[] password,
byte[] salt,
int log_rounds,
int[] cdata)
password - the password to hashsalt - the binary salt to hash with the passwordlog_rounds - the binary logarithm of the number
of rounds of hashing to applycdata - the plaintext to encryptpublic static String hashpw(String password, String salt)
password - the password to hashsalt - the salt to hash with (perhaps generated
using BCrypt.gensalt)public static String gensalt(int log_rounds, SecureRandom random)
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 usepublic static String gensalt(int log_rounds)
log_rounds - the log2 of the number of rounds of
hashing to apply - the work factor therefore increases as
2**log_rounds.public static String gensalt()
Copyright © 2016. All rights reserved.