spring boot配置文件加密、明文密码加密、properties 和 yml 互相转换
spring boot配置文件加密、明文密码加密、properties 和 yml 互相转换1.引入maven2.添加配置(yml格式的;properties 和 yml 在线转换)3.找到maven仓库下:org\jasypt\jasypt\1.9.3将内容进行加密4.常见问题及排查方法1.引入maven<dependency><groupId>com.github.ul
spring boot配置文件加密、明文密码加密、properties 和 yml 互相转换
1.引入maven
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.3</version>
</dependency>
2.添加配置(yml格式的;properties 和 yml 在线转换)
properties 和 yml 在线转换:properties 和 yml 在线转换
jasypt:
encryptor:
algorithm: PBEWithMD5AndDES #算法-固定写法一般没人改
password: 1234qwer #密钥
iv-generator-classname: org.jasypt.iv.NoIvGenerator #设置初始向量IV生成器的类名
3.找到maven仓库下:org\jasypt\jasypt\1.9.3将内容进行加密
-
打开到地方后-在地址栏输入
cmd
打开黑窗口
-
窗口打开后输入
java -cp jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="root" password=1234qwer algorithm=PBEWithMD5AndDES
java -cp jasypt-
版本根据自己的修改
.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input=“明文
” password=密钥
algorithm=算法
这三个值要和配置文件里一样 -
输入后回车
----OUTPUT----------------------下面的就是 root明文 加密后的内容
-
将内容复制出来(用鼠标选中加密生成的内容右击就可以复制)-替换掉配置文件里的内容—将配置中的密码root替换成刚刚加密的内容使用
ENC()
包起来;ENC()是可以改的—不想用的大家可以去百度怎么改
4.常见问题及排查方法
- 问题1
Failed to bind properties under 'spring.datasource.password' to java.lang.String: Reason: org.jasypt.encryption.pbe.config.SimpleStringPBEConfig.setIvGeneratorClassName(Ljava/lang/String;)V
- 问题2
Failed to bind properties under 'spring.datasource.password' to java.lang.String: Reason: Failed to bind properties under 'spring.datasource.password' to java.lang.String Action: Update your application's configuration
- 问题3
Description: An attempt was made to call the method org.jasypt.encryption.pbe.config.SimpleStringPBEConfig.setIvGeneratorClassName(Ljava/lang/String;)V but it does not exist. Its class, org.jasypt.encryption.pbe.config.SimpleStringPBEConfig, is available from the following locations: jar:file:/D:/yixing/maven/repository_uap/org/jasypt/jasypt/1.9.2/jasypt-1.9.2.jar!/org/jasypt/encryption/pbe/config/SimpleStringPBEConfig.class It was loaded from the following location: file:/D:/yixing/maven/repository_uap/org/jasypt/jasypt/1.9.2/jasypt-1.9.2.jar Action: Correct the classpath of your application so that it contains a single, compatible version of org.jasypt.encryption.pbe.config.SimpleStringPBEConfig
- 排查方法
- 先检查配置文件是否有问题、是否有多余的空格
- jasypt-spring-boot-starter.jar 是不是引入版本过高
- 不管jasypt-spring-boot-starter.jar是几点几的版本都可以加上
iv-generator-classname: org.jasypt.iv.NoIvGenerator
配置—不是只有3.0以上的才可以加 - 如果上面的都没问题,那就是jar包冲突的原因(问题3就是jar包冲突的原因)
查看冲突版本:
1.点击maven中的Show Dependencies(那两个向上的箭头)会弹出左面的视图
2.在视图中搜索加密用到的jar包-问题3中报的就是jasypt.jar包冲突那就直接搜索jasypt了
3.可以看到下面搜到了两个jasypt;点击其中一个就会定位到jasypt包的旁边还得在找一下才能找到jasypt包可以看到下面是1.9.3和1.9.2冲突了(然后我们可以找找1.9.3和1.9.2、能找到那个就把这个版本换成和另一个一样的就可以了)
更多推荐
所有评论(0)