首先,可以在官网中取得源代码http://www.mindrot.org/projects/jBCrypt/
然后通过Ant进行编译。编译之后得到jbcrypt.jar。也可以不需要进行编译,而直接使用源码中的java文件(本身仅一个文件)。
下面是官网的一个Demo。
复制代码
public class BCryptDemo {
public static void main(String[] args) {
// Hash a password for the first time
String password = "testpassword";
String hashed = BCrypt.hashpw(password, BCrypt.gensalt());
System.out.println(hashed);
// gensalt's log_rounds parameter determines the complexity
// the work factor is 2**log_rounds, and the default is 10
String hashed2 = BCrypt.hashpw(password, BCrypt.gensalt(12));
// Check that an unencrypted password matches one that has
// previously been hashed
String candidate = "testpassword";
//String candidate = "wrongtestpassword";
if (BCrypt.checkpw(candidate, hashed))
System.out.println("It matches");
else
System.out.println("It does not match");
}
}
复制代码