在工程中加入
maven
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
gradle
implementation "com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.2"
在application-local.yml中加入
jasypt:
encryptor:
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator
password: XyO8tet6i4dX14S #生产中使用命令行方式
修改密码为ENC()
形式
Jasypt生成密码参考:https://github.com/chenjiangtao/spring-boot-on-kubernetes#Jasypt
mysql:
jdbc-url: jdbc:mysql://localhost:4000/test?serverTimezone=Asia/Shanghai&allowLoadLocalInfile=true&useUnicode=true&characterEncoding=utf-8&useSSL=false&rewriteBatchedStatements=true
# username: test
# password: test
username: ENC(cMiMOtvRCdJK+4hazUKSXA==)
password: ENC(rQc8TdaC+7m5DqLS1rlN1g==)
driver-class-name: com.mysql.cj.jdbc.Driver
validation-query: select 1
在启动类加两个注解
@Configuration
@EnableEncryptableProperties
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
启动
java -jar -Djasypt.encryptor.password=XyO8tet6i4dX14S -DGATEWAY_SERVICE_EVN=local build/libs/app.jar
或者使用--spring.profiles.active=dev
java -jar -Djasypt.encryptor.password=XyO8tet6i4dX14S build/libs/app.jar --spring.profiles.active=local
更新盐
mvn jasypt:reencrypt -Djasypt.plugin.old.password=OLD -Djasypt.encryptor.password=NEW
ulisesbocchio参考:
https://github.com/ulisesbocchio/jasypt-spring-boot
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/100338.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...