使用pringboot对数据库地址进行加密的方法首先,需要在SpringBoot项目中导入依赖;com.GitHub.ulisesbocchiojasypt-spring-boot-starter2.0.0依赖导入好后,在springboo
使用pringboot对数据库地址进行加密的方法
首先,需要在SpringBoot项目中导入依赖;
依赖导入好后,在springboot中输入代码即可对数据库地址进行加密;
public class EncryptionPropertyConfig {
@Bean(name="encryptablePropertyResolver")
public EncryptablePropertyResolver encryptablePropertyResolver() {
return new EncryptionPropertyResolver();
}
class EncryptionPropertyResolver implements EncryptablePropertyResolver {
@Override
public String resolvePropertyValue(String value) {
if(StringUtils.isBlank(value)) {
return value;
}
// 值以DES@开头的均为DES加密,需要解密
if(value.startsWith("xxxxx@")) {
return resolveDESValue(value.substring(11));
}
// 不需要解密的值直接返回
return value;
}
private String resolveDESValue(String value) {
// 自定义DES密文解密
String decode="";
try{
decode = DESCode.decode(value);
}catch (Exception e){
e.printStackTrace();
System.out.println("解密失败!:"+ value);
}
System.out.println("value :"+value +" :"+decode);
return decode;
}
}
}
--结束END--
本文标题: springboot如何给数据库地址加密
本文链接: https://www.lsjlt.com/news/115123.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
2024-05-16
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0