关于java.security.Provider安全服务操作引起异常的问题解决

由于之前的项目需要访问非国际认可的国密SSL证书,在HttpClient的工具类代码中我删除了“SunEC”的安全Provider。

Security.removeProvider("SunEC");

但是在后续的项目在Linux的执行中访问其他网站的时候产生了一些异常

javax.net.ssl.SSLException: java.lang.RuntimeException: java.security.NoSuchAlgorithmException: EC A
lgorithmParameters not available

通过源码追踪发现是在获取不到EC的Provider而产生的问题

private static AlgorithmParameters getECParameters(Provider var0) {
        try {
            return var0 != null ? AlgorithmParameters.getInstance("EC", var0) : AlgorithmParameters.getInstance("EC");
        } catch (NoSuchAlgorithmException var2) {
            throw new RuntimeException(var2);
        }
    }

解决办法也很简单,通过访问的地址来区分,分发到不同的逻辑中并添加代码

Security.addProvider(new SunEC());
posted @ 2021-01-29 13:23  αSothis  阅读(1205)  评论(0)    收藏  举报