1、BCrypt加密 ,比对
public static void main(String[] args) {
String password = "123456";
String hashpw = BCrypt.hashpw(password, BCrypt.gensalt());
System.out.println("[hashpw]:"+hashpw);
boolean matches = new BCryptPasswordEncoder().matches(password, hashpw);
System.out.println("[matches]:"+matches);
}
2、对称加密——base64加解密
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class EncryptUtil {
/**
* BASE64解密
* @throws Exception
*/
public static byte[] decryptBASE64(String key) throws Exception {
return (new BASE64Decoder()).decodeBuffer(key);
}
/**
* BASE64加密
*/
public static String encryptBASE64(byte[] key) throws Exception {
return (new BASE64Encoder()).encodeBuffer(key);
}
public static void main(String[] args) throws Exception {
String ss = "123456";
String encryptBASE64 = encryptBASE64(ss.getBytes());
System.out.println(encryptBASE64);
byte[] bytes = decryptBASE64(encryptBASE64);
System.out.println(new String(bytes));
}
public static void main(String[] args) throws Exception {
String ss = "123456";
String encryptBASE64 =(new BASE64Encoder()).encodeBuffer(ss.getBytes());
System.out.println(encryptBASE64);
System.out.println(new String((new BASE64Decoder()).decodeBuffer(encryptBASE64)));
}
}