我想存储2个不同的领域编程密钥库。下面是为域A加载密钥库的代码。我想为域B加载它。这两个密钥库将在同一个应用程序中使用。
public static SSLContext createSSLContext() throws Exception{
KeyStore clientStore = createKeyStore();
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(clientStore, "password".toCharArray());
KeyManager[] kms = kmf.getKeyManagers();
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(kms, null, new SecureRandom());
return sslContext;
}
public static KeyStore createKeyStore() throws Exception{
KeyStore clientStore = KeyStore.getInstance("PKCS12");
try {
clientStore.load(new ByteArrayInputStream("PKCS12 info"), "password".toCharArray());
} catch(Exception e){
e.printStackTrace();
}
return clientStore;
}发布于 2020-10-28 08:06:41
正如dave-thompson-085提到的,我缺少TrustStore密钥。以下帖子中的代码片段很有帮助。Programmatically Import CA trust cert into existing keystore file without using keytool
https://stackoverflow.com/questions/64473774
复制相似问题