使用@SpringBootApplication注解启动的项目,只需增加maven依赖
我们对信息加解密是使用这个jar包的:
编写加解密测试类:
package cn.linjk.ehome; import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; import org.jasypt.encryption.pbe.config.EnvironmentPBEConfig; import org.junit.Test; public class JasyptTest { @Test public void testEncrypt() throws Exception { StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); EnvironmentPBEConfig config = new EnvironmentPBEConfig(); config.setAlgorithm("PBEWithMD5AndDES"); // 加密的算法,这个算法是默认的 config.setPassword("test"); // 加密的密钥 standardPBEStringEncryptor.setConfig(config); String plainText = "88888888"; String encryptedText = standardPBEStringEncryptor.encrypt(plainText); System.out.println(encryptedText); } @Test public void testDe() throws Exception { StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); EnvironmentPBEConfig config = new EnvironmentPBEConfig(); config.setAlgorithm("PBEWithMD5AndDES"); config.setPassword("test"); standardPBEStringEncryptor.setConfig(config); String encryptedText = "ip10XNIEfAMTGQLdqt87XnLRsshu0rf0"; String plainText = standardPBEStringEncryptor.decrypt(encryptedText); System.out.println(plainText); } }
加密串拿到了,现在来修改application.yml的配置:
我们把加密串放在ENC({加密串})即可。
启动时需要配置 秘钥
将秘钥加入启动参数
以上就是SpringBoot项目中如何利用application.yml文件配置数据库密码加密的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号