我正在尝试对需要证书的axis2 api进行api调用。我将其导入位于/lib/security中的java密钥库。我验证了在几个方法中成功导入了证书(在方法上也是在下面的代码中,证书不为null)。
我可以使用默认密码从密钥库获取证书。但是我得到了不可恢复的密钥异常:当我尝试为sslcontext使用相同的密钥库和密码时,无法恢复密钥异常。有人能帮我吗?
final char sep = File.separatorChar;
File dir = new File(System.getProperty("java.home") + sep + "lib" + sep + "security");
File file = new File(dir, "cacerts");
InputStream localCertIn = new FileInputStream(file);
String password = "changeit" ;
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(localCertIn, password.toCharArray());
String alias = "alias name";
X509Certificate certificate = (X509Certificate)keystore.getCertificate(alias);
//Certificate is not null
SSLContext sslContext = SSLContexts.custom()
.loadKeyMaterial(keystore, password.toCharArray())
.build();
//Throws the following error
暂无答案!
目前还没有任何答案,快来回答吧!