<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.2</version>
</dependency>
@EnableEncryptableProperties
public class Test {
public static void main(String[] args) {
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
EnvironmentPBEConfig config = new EnvironmentPBEConfig();
//加密的算法,默认
config.setAlgorithm("PBEWithMD5AndDES");
//加密的盐
config.setPassword("password");
standardPBEStringEncryptor.setConfig(config);
//需要加密的密码
String password = "root";
String encrypt = standardPBEStringEncryptor.encrypt(password);
System.out.println(encrypt);
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword("password");
System.out.println(encryptor.decrypt(encrypt));
}
}
password: ENC(Kn7cQm1DtLutH/27dTPi3D(Q/ILQbOKK)
加密的密码放在括号里面
#jasypt加密的密匙
jasypt:
encryptor:
password: root
java -jar -Djasypt.encryptor.password=root XXX-xxxx.jar