KeyStore ks = KeyStore.getInstance("PKCS12");
FileInputStream fis = new FileInputStream("/path/to/file.p12");
ks.load(fis, "password".toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, "password".toCharArray());
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), null, null);
此代码工作正常。但是有可能在这种情况下使用keystore.jks吗?例如,我使用带有一些别名的pkcs12import工具将file.p12导入到keystore.jks中。然后我使用System.setProperty(“javax.net.ssl.keyStore”,“C:/Sun/SDK/jdk/jre/lib/security/keystore.jks”);并且不在java代码中编写证书路径和密码,而是从该keystore.jks文件中获取