栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

spring boot配置文件加密、明文密码加密、properties 和 yml 互相转换

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

spring boot配置文件加密、明文密码加密、properties 和 yml 互相转换

spring boot配置文件加密、明文密码加密、properties 和 yml 互相转换
  • 1.引入maven
  • 2.添加配置(yml格式的;properties 和 yml 在线转换)
  • 3.找到maven仓库下:orgjasyptjasypt1.9.3将内容进行加密
  • 4.常见问题及排查方法

1.引入maven

	com.github.ulisesbocchio
	jasypt-spring-boot-starter
	3.0.3


	org.jasypt
	jasypt
	1.9.3

2.添加配置(yml格式的;properties 和 yml 在线转换)

properties 和 yml 在线转换:properties 和 yml 在线转换

jasypt:
  encryptor:
    algorithm: PBEWithMD5AndDES		#算法-固定写法一般没人改
    password: 1234qwer				#密钥
    iv-generator-classname: org.jasypt.iv.NoIvGenerator	#设置初始向量IV生成器的类名
3.找到maven仓库下:orgjasyptjasypt1.9.3将内容进行加密
  1. 打开到地方后-在地址栏输入cmd-打开黑窗口

  2. 窗口打开后输入

    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=算法 这三个值要和配置文件里一样

  3. 输入后回车
    ----OUTPUT----------------------下面的就是 root明文 加密后的内容

  4. 将内容复制出来(用鼠标选中加密生成的内容右击就可以复制)-替换掉配置文件里的内容—将配置中的密码root替换成刚刚加密的内容使用ENC()包起来;ENC()是可以改的—不想用的大家可以去百度怎么改

4.常见问题及排查方法
  1. 问题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. 问题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. 问题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
    
  4. 排查方法
    1. 先检查配置文件是否有问题、是否有多余的空格
    2. jasypt-spring-boot-starter.jar 是不是引入版本过高
    3. 不管jasypt-spring-boot-starter.jar是几点几的版本都可以加上iv-generator-classname: org.jasypt.iv.NoIvGenerator配置—不是只有3.0以上的才可以加
    4. 如果上面的都没问题,那就是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、能找到那个就把这个版本换成和另一个一样的就可以了)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/287689.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号