com.github.xiaoyuge5201.encryption.BcryptUtils Maven / Gradle / Ivy
package com.github.xiaoyuge5201.encryption;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
/**
* @author xiaoyuge
*/
public class BcryptUtils {
/**
* 使用Bcrypt加密
* $是分割符,无意义;2a是bcrypt加密版本号;10是cost的值;而后的前22位是salt值;再然后的字符串就是密码的密文了
* @param plaintext 明文
* @return
*/
public static String encode(String plaintext) {
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
return bCryptPasswordEncoder.encode(plaintext);
}
/**
* 判断明文和密文是否匹配
* @param cipherText 密文
* @param plaintext 明文
* @return 匹配结果
*/
public static Boolean matches(String cipherText, String plaintext) {
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
return bCryptPasswordEncoder.matches(cipherText, plaintext);
}
}