我在尝试为KeyStore.TrustedCertificateEntry设置证书时尝试另一种方法找到了答案。它基于Vit Hnilica
从密钥库加载证书时的回答。我将用这个答案来回答这个问题,因为大多数堆栈溢出答案都以“转换为
openssl,然后使用
keytool…”
开头。
String CA_FILE = ...;FileInputStream fis = new FileInputStream(CA_FILE);X509Certificate ca = (X509Certificate) CertificateFactory.getInstance( "X.509").generateCertificate(new BufferedInputStream(fis));KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());ks.load(null, null);ks.setCertificateEntry(Integer.toString(1), ca);TrustManagerFactory tmf = TrustManagerFactory .getInstance(TrustManagerFactory.getDefaultAlgorithm());tmf.init(ks);...
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)