网站首页 > 博客文章 正文
在Spring Boot中,可以使用Jasypt(Java Simplified Encryption)来对敏感的配置信息进行加密。Jasypt是一个简单的加密库,支持在配置文件中使用占位符来引用加密后的值。
下面是使用 Jasypt 加密敏感配置信息的步骤
添加Jasypt依赖
首先,在 Maven的配置文件中添加Jasypt的依赖。
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
在配置文件中加密敏感信息
在application.yml或application.properties文件中,使用ENC()函数将敏感信息进行加密,并将加密后的值放置在占位符中。例如
db:
username: ENC(encrypted_username)
password: ENC(encrypted_password)
使用Jasypt工具加密配置信息
用Jasypt提供的命令行工具或Java API来加密敏感信息。命令行工具可以在命令行中执行,Java API则可以在代码中调用。
使用命令行工具
java -cp jasypt-3.0.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="your_sensitive_data" password="your_encryption_password" algorithm=PBEWithMD5AndDES
这将输出加密后的值,将其复制并替换application.yml中的encrypted_username和encrypted_password。
使用Java API
public class JasyptExample {
public static void main(String[] args) {
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword("your_encryption_password");
String encryptedUsername = encryptor.encrypt("your_sensitive_username");
String encryptedPassword = encryptor.encrypt("your_sensitive_password");
System.out.println("Encrypted Username: " + encryptedUsername);
System.out.println("Encrypted Password: " + encryptedPassword);
}
}
启动应用程序
在启动Spring Boot应用程序时,Jasypt将会自动解密配置文件中的敏感信息,并注入到对应的属性中。
这样,敏感的配置信息就会以加密的形式存储在配置文件中,只有知道加密密码的人才能解密并查看真实的敏感信息,提高了配置信息的安全性。
猜你喜欢
- 2024-11-13 spring boot配置文件敏感字段加密
- 2024-11-13 Spring Boot数据库密码加密的配置方法
- 2024-11-13 Spring Boot安全之application配置信息加密
- 2024-11-13 如何在SpringBoot项目中实现加密?
- 2024-11-13 SpringBoot进阶-SpringBoot如何实现配置文件脱敏?
- 2024-11-13 加密SpringBoot配置文件技巧(加密pdf文件如何解密编辑)
- 2024-11-13 Spring Boot版本和Jasypt版本的兼容性问题?
- 2024-11-13 SpringBoot加密配置属性(springboot配置密码加密)
- 2024-11-13 SpringCloud-OAuth2(二):实战篇(oauth2.0 springcloud)
- 2024-11-13 SpringBoot 配置文件这样加密,才足够安全!
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)