gpt4 book ai didi

java - 如何在 Spring 的属性文件中以加密形式存储密码

转载 作者:IT老高 更新时间:2023-10-28 13:52:54 36 4
gpt4 key购买 nike

我是 Spring 框架的新手,我正在使用 Spring 框架来管理我的数据库连接等等。应用程序从属性文件中读取我的数据库连接参数。我需要的是将我的连接密码加密存储在属性文件中。这是我的数据源 xml 文件

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>file:${DBConfigFile}</value>
</property>
</bean>

<bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="initialPoolSize"><value>3</value></property>
<property name="minPoolSize"><value>3</value></property>
<property name="maxPoolSize"><value>50</value></property>
<property name="idleConnectionTestPeriod"><value>200</value></property>
<property name="acquireIncrement"><value>1</value></property>
<property name="maxStatements"><value>0</value></property>
<property name="numHelperThreads"><value>3</value></property>
</bean>

</beans>

我想将加密的密码写入属性文件,我想知道 Spring 是否可以使用算法自动解密它。是否可以通过配置。提前谢谢你。

最佳答案

据我所知,Spring 不支持此功能,但其他一些项目可能会有所帮助:

关于java - 如何在 Spring 的属性文件中以加密形式存储密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11645477/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com