Spring 中使用jasypt对配置文件(.properties)中密码加密
来源:互联网 发布:魔法王座神器升级数据 编辑:程序博客网 时间:2024/05/19 23:17
spring配置中经常使用placeholder来加载一个应用配置文件(.properties),但是其中的各种密码以明文显示出来总该是不好。
不过可以利用jasypt这个框架来扩展这个加密功能,需要用到jasypt中的icu4j-version.jar、jasypt-version-lite.jar、jasypt-version.jar和jasypt-spring31-version.jar
首先,注释掉原有的placeholder加载方式
- <!--<context:property-placeholder location="/WEB-INF/config.properties"/> -->
- <!-- decrypt password in config.properties -->
- <bean id="environmentVariablesConfiguration"
- class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
- <property name="algorithm" value="PBEWithMD5AndDES" />
- <property name="password" value="root" />
- </bean>
- <bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
- <property name="config" ref="environmentVariablesConfiguration" />
- </bean>
- <bean id="propertyConfigurer"
- class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer">
- <constructor-arg ref="configurationEncryptor" />
- <property name="locations">
- <list>
- <value>/WEB-INF/config.properties</value>
- </list>
- </property>
- <property name="fileEncoding" value="utf-8" />
- </bean>
- public static void main(String[] args) {
- //PBEWithMD5AndDES
- BasicTextEncryptor encryptor = new BasicTextEncryptor();
- encryptor.setPassword("root");
- String encrypted = encryptor.encrypt("xxxx");
- System.out.println(encrypted);
- }
- jdbc.password=ENC(jHv0WdiTLJFmOO08RQtUpg==)
这样的密文虽然还是很容易被decode出来,但终究不是明文显示。
个人认为最好的办法可能是 自己去实现一个spring的 place holder,利用md5来匹配配置文件中的密文是否正确。
0 0
- Spring 中使用jasypt对配置文件(.properties)中密码加密
- Spring 中使用jasypt对配置文件(.properties)中密码加密
- Spring 中使用jasypt对配置文件(.properties)中密码加密
- Java jasypt对.properties配置文件密码加密
- 使用jasypt对spring boot的datasource中数据库密码加密
- 使用jasypt对springboot的datasource密码加密
- 使用jasypt对springboot的datasource密码加密
- 在Spring配置文件中使用properties文件
- Spring中使用外部的properties配置文件
- SpringBoot中加密包对配置文件中的密码进行加密
- jasypt结合spring加密
- spring jasypt加密
- java spring中对properties属性文件加密及其解密
- java spring中对properties属性文件加密及其解密
- java spring中对properties属性文件加密及其解密
- java spring中对properties属性文件加密及其解密
- java spring中对properties属性文件加密及其解密
- java spring中对properties属性文件加密及其解密
- springAOP之aspectJ(一)
- Android AlertDialog 无法弹出输入法
- java中 关于运算符注意的事项
- (UVa 10047) The Monocycle -- BFS 4维状态
- error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
- Spring 中使用jasypt对配置文件(.properties)中密码加密
- 好用的脚本
- Excel导入和导出
- 感悟随笔
- 友盟崩溃日志分享,dsym工具
- GNU GLOBAL Source Code Tag System浏览源码,很方便
- java Socket用法详解
- iFrame请求数据
- 版本更新下载