1.对于SpringBoot项目,直接通过引入jasypt-spring-boot-starter
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.4</version>
</dependency>
2.在启动类上添加一个@EnableEncryptableProperties,如果不想要整个Spring的配置文件都启用加密的字段属性,还可以自己指定对应加密的配置文件路径 例;@EncryptablePropertySource({"classpath:encrypted.properties"})
3.添加maven插件
<plugin>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-maven-plugin</artifactId>
<version>3.0.4</version>
</plugin>
4.执行加密命令 mvn jasypt:encrypt-value -Djasypt.encryptor.password="TKzhc3fz" -Djasypt.plugin.value="123456"
5.解密命令 mvn jasypt:decrypt-value -Djasypt.encryptor.password="TKzhc3fz" -Djasypt.plugin.value="加密后信息"