当前位置:网站首页>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);
}
}
边栏推荐
- Get system volume across platforms in unity
- 【QT小点】QT下载链接
- Configuring the help class iconfiguration in C # NETCORE
- 1317. 将整数转换为两个无零整数的和
- EasyExcel合并相同内容单元格及动态标题功能的实现
- Acwing's 57th weekly match -- BC question is very good
- 双位置继电器RXMVB2 R251 204 110DC
- leetcode298周赛记录
- KubeSphere 集群配置 NFS 存储解决方案-收藏版
- OpenCV的轮廓检测和阈值处理综合运用
猜你喜欢

C Primer Plus 第11章_字符串和字符串函数_代码和练习题

多线程基础部分Part3

LeetCode-515. 在每个树行中找最大值

How JQ gets the reciprocal elements

Some articles about component packaging and my experience

How win 10 opens the environment variables window

STM32 reads IO high and low level status

Double position relay rxmd2-1mrk001984 dc220v

汇编语言-王爽 第9章 转移指令的原理-笔记

QT using Valgrind to analyze memory leaks
随机推荐
《汇编语言-王爽》第3章笔记及实验
项目-h5列表跳转详情,实现后退不刷新,修改数据则刷新的功能(记录滚动条)
[FPGA] realize the data output of checkerboard horizontal and vertical gray scale diagram based on bt1120 timing design
C Primer Plus 第11章_字符串和字符串函数_代码和练习题
WebRTC系列-网络传输之7-ICE补充之提名(nomination)与ICE_Model
【Cocos Creator 3.5.1】input. Use of on
【Cocos Creator 3.5.1】this. node. Use of getposition (this.\u curpos)
How win 10 opens the environment variables window
竣达技术丨多品牌精密空调集中监控方案
【FPGA】 基于FPGA分频,倍频设计实现
Opencv实现对象跟踪
【QT小作】使用结构体数据生成读写配置文件代码
【QT小记】QT中正则表达式QRegularExpression的基本使用
[cocos creator 3.5.1] addition of coordinates
Codeforces Round #802 (Div. 2)
IAR Systems全面支持芯驰科技9系列芯片
双位置继电器RXMD2-1MRK001984 DC220V
STM32 reads IO high and low level status
QListWidgetItem上附加widget
Spark 之 Projection