简体   繁体   English

Spring Boot应用程序属性解密jpa密码

[英]Spring Boot application properties decrypting jpa password

Hi I have a Spring Boot application properties file where I configured the JPA datasource details such as username, url, password, etc. The password I have encrypted using my own encryption method from another jar file.嗨,我有一个 Spring Boot 应用程序属性文件,我在其中配置了 JPA 数据源详细信息,例如用户名、url、密码等。我使用我自己的加密方法从另一个 jar 文件加密了密码。 So the password is something like所以密码是这样的

spring.datasource.password="ASDFIOM#KFS(@JSDF@N2"

I made up a random password for the sake of an example.为了举例,我编了一个随机密码。 But now I want to decrypt that password but the moment you run spring boot it opens a connection with the DB using the JPA datasource details.但是现在我想解密该密码,但是当您运行 spring boot 时,它会使用 JPA 数据源详细信息打开与数据库的连接。

How do I decrypt this password before Spring Boot makes a connection with the DB with JPA's datasource如何在 Spring Boot 与带有 JPA 数据源的 DB 建立连接之前解密此密码

You need to specify the dataSource programmatically :您需要以编程方式指定数据源:

https://www.baeldung.com/spring-boot-configure-data-source-programmatic#configuring-a-datasource-bean https://www.baeldung.com/spring-boot-configure-data-source-programmatic#configuring-a-datasource-bean

And in the line :并在该行中:

 dataSourceBuilder.password("");

Use your custom method to decrypt.使用您的自定义方法进行解密。

 dataSourceBuilder.password(decrypt(dbPassPropertieCrypted));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM