当前位置:网站首页>yaml文件加密
yaml文件加密
2022-06-27 05:54:00 【衬衫boy】
Springboot和jasypt
使用jasypt加密yaml文件中的敏感信息
1、所需依赖
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
2、使用在yaml文件中加入所需密钥
jasypt:
encryptor:
password: qwerty #密钥(自定义)
algorithm: PBEWithMD5AndDES #加密方式
3、密钥生成
java -cp jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="123456" password="qwerty" algorithm=PBEWithMD5AndDES
input:密码(自定义)
password:自定义的密钥
algorithm:加密方式
4、把步骤3的命令在jasypt依赖下执行(cmd)

5、加密方法(以连接数据库的账号密码为例)
@Autowired
private StringEncryptor stringEncryptor;
@Test
public void encryptPwd(){
//加密
String username = stringEncryptor.encrypt("root");
System.out.println("加密username:"+username);
String decryptUserName = stringEncryptor.decrypt(username);
System.out.println("解密username"+decryptUserName);
String pwd = stringEncryptor.encrypt("123456");
System.out.println("加密密码:"+pwd);
String decryptPwd = stringEncryptor.decrypt(pwd);
System.out.println("解密密码"+decryptPwd);
}
6、再根据加密出来的账号密码替换掉yaml文件里的账号密码即可
username: ENC(+9yooqRfPCwdB2a+qMKZUA==)
password: ENC(vBoYnMFjRK8JUWTJo2XQJA==)
一定要加ENC()不然识别不了
也可以在springboot的启动类里加密钥(在启动类里加就不需要在配置文件中写了,只需要指定加密方式即可)
public class DemoApplication {
public static void main(String[] args) {
System.setProperty("jasypt.encryptor.password", "qwerty");
SpringApplication.run(DemoApplication.class, args);
}
}
边栏推荐
- EasyExcel合并相同内容单元格及动态标题功能的实现
- Formation and release of function stack frame
- Implementation of easyexcel's function of merging cells with the same content and dynamic title
- Epics record reference 5 -- array analog input recordarray analog input (AAI)
- 数据库-索引
- 【FPGA】UART串口_V1.1
- Built in functions of spark
- Unity point light disappears
- 洛谷P4683 [IOI2008] Type Printer 题解
- Unicast, multicast and broadcast of IP network communication
猜你喜欢

思维的技术:如何破解工作生活中的两难冲突?

Reading graph augmentations to learn graph representations (lg2ar)

Create a basic WDM driver and use MFC to call the driver

What is BFC? What's the usage?

Leetcode99 week race record

Leetcode298 weekly race record

Gao Xiang slam14 lecture - note 1

Free SSH and telnet client putty

RTP sending PS stream tool (open source)

Avoid asteroids
随机推荐
网易云音乐params和encSecKey参数生成代码
QT using Valgrind to analyze memory leaks
Codeforces Round #802 (Div. 2)
Experience oceanbase database under win10
Leetcode99 week race record
项目-h5列表跳转详情,实现后退不刷新,修改数据则刷新的功能(记录滚动条)
Open the door small example to learn ten use case diagrams
STM32 reads IO high and low level status
IP网络通信的单播、组播和广播
IAR Systems全面支持芯驰科技9系列芯片
Discussion on streaming media protocol (MPEG2-TS, RTSP, RTP, RTCP, SDP, RTMP, HLS, HDS, HSS, mpeg-dash)
Netease cloud music params and encseckey parameter generation code
Using domain name forwarding mqtt protocol, pit avoidance Guide
【Cocos Creator 3.5.1】event.getButton()的使用
Neo4j community conflicts with neo4j desktop
[FPGA] realize the data output of checkerboard horizontal and vertical gray scale diagram based on bt1120 timing design
Create a basic WDM driver and use MFC to call the driver
EasyExcel合并相同内容单元格及动态标题功能的实现
[cocos creator 3.5.1] addition of coordinates
【入门】正则表达式基础入门笔记