https://www.cnblogs.com/xingzc/p/8624007.html
import org.mindrot.jbcrypt.BCrypt;
public class Uitl {
public static String hashed(String password) {
return BCrypt.hashpw(password, BCrypt.gensalt(12));
}
public static boolean check(String password, String hashed) {
return BCrypt.checkpw(password, hashed);
}
public static void main(String[] args) {
System.out.println(hashed("123"));
System.out.println(check("123", "$2a$12$uRNV96zAUq/ixZ14zo7yQOYfLtImM43mrHnsSqhdQigZQj4h7GOpC"));
}
//
}
由于md5
不安全,即MD5(x)=MD5(x')
存在,故业界现在更多使用BCrypt
,该加密每次产生的盐值都不一样,另外可以设置rounds值来调整work factor
,可以将自身hash之后的值,再hash rounds的对数值次,从而当硬件水平提升时,可以调大该值,来提高破解的花费的时间