您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

springboot配置文件数据库账号密码加密

bubuko 2022/1/25 19:44:54 java 字数 5974 阅读 1015 来源 http://www.bubuko.com/infolist-5-1.html

配置文件配置暴露一些密码问题处理: jasypt?是一个简单易用的加解密Java库 相关源码github地址 github:https://github.com/ulisesbocchio/jasypt-spring-boot https://github.com/gxing19/Spring-Bo ...

配置文件配置暴露一些密码问题处理:

jasypt 是一个简单易用的加解密Java库

相关源码github地址

github:https://github.com/ulisesbocchio/jasypt-spring-boot

https://github.com/gxing19/Spring-Boot-Example/tree/master/spring-boot-password-encrypt

1、添加依赖:

<!-- jasypt加密 -->
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>

2、环境变量设置 jasypt 密钥:

jasypt.encryptor.password=vh^onsYFUx^DMCKK

不让密钥在配置文件中显示,可以在启动应用时将密码做为启动参数传递给应用
在运行应用时设置环境变量,如下:
java -jar target/jasypt-spring-boot-demo-0.0.1-SNAPSHOT.jar --jasypt.encryptor.password=password

或将密钥作为命令行参数传递运行应用
java -Djasypt.encryptor.password=password -jar target/jasypt-spring-boot-demo-0.0.1-SNAPSHOT.jar

3、编写测试代码生成密文
package com.aisino.cma;

import org.jasypt.encryption.StringEncryptor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* <p>
* 前端控制器
* </p>
*
* @author ranqw
* @since 2020-06-03
*/

@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationProperties {

@Autowired
StringEncryptor encryptor;

@Test
public void jacketEncrypt() {

//加密
/*String name = encryptor.encrypt("invoice");
String password = encryptor.encrypt("user99");
System.out.println("name 密文: " + name);
System.out.println("password 密文: " + password);*/

//解密
/*String decrypt1 = encryptor.decrypt(name);
String decrypt2 = encryptor.decrypt(password);
System.out.println(decrypt1 + "------------" + decrypt2);*/
}

}

4、重启应用,查看数据库是否连接成功

 

springboot配置文件数据库账号密码加密

原文:https://www.cnblogs.com/small-panda/p/13037588.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶