【问题标题】:Encrypting/Decrypting database password programatically in SpringBoot在 Spring Boot 中以编程方式加密/解密数据库密码
【发布时间】:2022-01-16 07:32:33
【问题描述】:

第一次在这里发帖求助!如您所知,要添加数据源(在我的情况下为 MySql),我需要使用以下行指定数据源的用户名和密码(在我的情况下为 demopassword):

spring.datasource.username=root
spring.datasource.password=demopassword

我有一个项目,客户要求我在程序中加密和解密密码,就像它包含在创建 SessionManager 的 HibernateUtil 类中一样。我尝试使用 jasypt,成功加密了密码,但我还必须在应用程序属性中保留 jasypt 所需的密钥。像下面的例子:

spring.datasource.username=root
spring.datasource.password=ENC(B8xLWaCTFe38G5gbICDxyg==)
jasypt.encryptor.password=test

有什么方法可以实现吗?我不一定需要使用 application.properties。我需要以编程方式输入、加密和解密数据库密码。提前致谢!

【问题讨论】:

    标签: mysql database spring-boot encryption


    【解决方案1】:

    您可以使用Spring Cloud Config encryption 来执行此操作。使用 Spring Boot CLI 加密您的数据后,获取生成的加密字符串并在其前面加上 {cipher},例如 '{cipher}lakjd98iyuolh98ytohaglj098u0u0[n='。您需要在运行应用程序时添加 -DENCRYPT_KEY=key 或将其作为环境变量。 key 值是用于使用 Spring Boot CLI 加密数据的值。

    【讨论】:

      猜你喜欢
      • 2017-01-27
      • 1970-01-01
      • 1970-01-01
      • 2021-12-02
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多