承接国内外服务器租用托管、定制开发、网站代运营、网站seo优化托管接单、网站代更新,新老站点皆可!!咨询QQ:3787320601

地址:springboot如何给数据库地址加密

管理员 2023-03-31 09:37:16 互联网圈 45 ℃ 0 评论 1634字 收藏

springboot如何给数据库地址加密

springboot如何给数据库地址加密

使用pringboot对数据库地址进行加密的方法

1.首先,需要在springboot项目中导入依赖;

com.github.ulisesbocchio

jasypt-spring-boot-starter

2.0.0

2.依赖导入好后,在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;

}

}

}

文章来源:丸子建站

文章标题:地址:springboot如何给数据库地址加密

https://www.wanzijz.com/view/5763.html

X

截屏,微信识别二维码

微信号:weimawl

(点击微信号复制,添加好友)

打开微信