com.github.dennisit.vplus.data.utils.JasyptUtils Maven / Gradle / Ivy
package com.github.dennisit.vplus.data.utils;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
public class JasyptUtils {
/**
* 编码 默认算法为"PBEWithMD5AndDES"
*
* @param keyt 秘钥
* @param source 原始数据
* @return 这里每次加密后的密文结果都不一样
*/
public static String encrypt(String keyt, String source) {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword(keyt);
encryptor.setAlgorithm("PBEWithMD5AndDES");
return encryptor.encrypt(source);
}
/**
* 解码 默认算法为"PBEWithMD5AndDES"
*
* @param keyt 秘钥
* @param source ji
* @return 解码结果
*/
public static String decrypt(String keyt, String source) {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword(keyt);
encryptor.setAlgorithm("PBEWithMD5AndDES");
return encryptor.decrypt(source);
}
}