我想這個皮膚貓:Use PEM Encoded CA Cert on filesystem directly for HTTPS request?另一種方式。爲KeyStore.TrustedCertificateEntry設置證書?
Java有一個類KeyStore.TrustedCertificateEntry
,但我無法弄清楚如何將證書加載到其中。我的代碼類似於以下:
import java.security.KeyStore.TrustedCertificateEntry;
...
X509Certificate ca = (X509Certificate) CertificateFactory(...);
KeyStore ks = TrustedCertificateEntry(ca);
和:
X509Certificate ca = (X509Certificate) CertificateFactory(...);
KeyStore ks = KeyStore.TrustedCertificateEntry(ca);
和:
X509Certificate ca = (X509Certificate) CertificateFactory(...);
KeyStore ks = new KeyStore.TrustedCertificateEntry(ca);
和:
X509Certificate ca = (X509Certificate) CertificateFactory(...);
KeyStore ks = new KeyStore.TrustedCertificateEntry(ca);
該計劃將失敗,並錯誤編譯:
SuperCert.java:33: error: cannot find symbol
KeyStore ks = TrustedCertificateEntry(ca);
^
symbol: method TrustedCertificateEntry(X509Certificate)
location: class TestCert
加載我的X509證書到KeyStore
後,我計劃在TrustManagerFactory
使用它,並最終抓取網頁與HttpsURLConnection
。
如何裝載一個X509Certificate
到TrustedCertificateEntry
?