【Druid】数据库链接加密

在命令行中执行如下命令:

java -cp druid-1.0.16.jar com.alibaba.druid.filter.config.ConfigTools testpw

输出

 privateKey:MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAp0Uml1u17Pr+qIEYzdzXg8nw4r2Wo+fQZbOxIkd6EnCRbkv6neQ8Ajm9XhSlJtcDRLAiF0JOvh/g9pWcjBd3lwIDAQABAkBNeFB8T4R9wm3JeykSx1KlfhTr3uTy+r1hLQ1AFByshufiS8TbUm0JCJgjdK7KE5HKeSuuv/6mZk6xF208kLDBAiEA4Wd0bTTpz9dFAavPaBIUk+XCKVNAjNXtwqwCG4EmjbcCIQC9+Zp4raVt3huP8sR5JpYOU+o773hwSXdtzfhMEXplIQIhAMrF8/IucMyeHyEiu+ImqcZnIiVlFKPd7Bd+ACNYKyO/AiAZvOpntSb3hqL3Uq25uDeWQ1o1upD3rYxnrQMZ0zhg4QIhAJN8XxM7FJRz82MGK70h4WFJqXTSlH5ztr06iAVDI/ug
 publicKey:MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKdFJpdbtez6/qiBGM3c14PJ8OK9lqPn0GWzsSJHehJwkW5L+p3kPAI5vV4UpSbXA0SwIhdCTr4f4PaVnIwXd5cCAwEAAQ== 
 password:FYlUzguXyxMln0h9uyVNA3EU2il1fc/MPzJiAbp5BH7LZGiQMs+Vp4KnLVF4zAAh4x9kPAS/IIqL/imuDuqYCA==

Druid中的ConfigTolls可以解析

import com.alibaba.druid.filter.config.ConfigTools;


public class testDruidPassword{
    public static void test() throws Exception {

        String publickey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKdFJpdbtez6/qiBGM3c14PJ8OK9lqPn0GWzsSJHehJwkW5L+p3kPAI5vV4UpSbXA0SwIhdCTr4f4PaVnIwXd5cCAwEAAQ==";
        String password = "FYlUzguXyxMln0h9uyVNA3EU2il1fc/MPzJiAbp5BH7LZGiQMs+Vp4KnLVF4zAAh4x9kPAS/IIqL/imuDuqYCA==";

        System.out.println( ConfigTools.decrypt(publickey, password) );

        String pw = ConfigTools.encrypt("testpw");

        System.out.println(pw);

        System.out.println(pw.equals(password));

    }

    public static void main(String[] args) throws Exception {
        test();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值