[英]How do I import a trusted certificate into an existing keystore programmatically?
[英]how to programmatically acces the window and mac trusted certificate store
使用keytool實用程序創建自簽名的Java密鑰庫和證書文件。 能夠通過使用mmc.exe命令轉到證書控制台,將證書添加到Windows信任存儲區。
但無論如何都要以編程方式將證書添加到Windows信任存儲中。 並且對於MAC系統也需要相同的東西。
感謝任何建議。
下面是Windows / MAC的代碼片段,用於在信任庫中添加證書。
窗口:
KeyStore root = KeyStore.getInstance("Windows-ROOT","SunMSCAPI");
root.load(null,null);
/* certificate must be DER-encoded */
FileInputStream in = new FileInputStream("yourcertificate.cer");
X509Certificate cacert = (X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(in);
root.setCertificateEntry("certificatealiasname", cacert);
在Windows中,它成功地在信任庫中添加證書,但由於沒有管理員權限,某些系統無法運行。 因此,在這些機器中,如果以管理員身份登錄或為用戶提供一些管理員權限,它將起作用。
蘋果電腦:
KeyStore root = KeyStore.getInstance("KeychainStore", "Apple");
root.load(null);
/* certificate must be DER-encoded */
FileInputStream in = new FileInputStream("yourcertificate.cer");
X509Certificate cacert = (X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(in);
root.setCertificateEntry("certificatealiasname", cacert);
root.store(null, null);
它能夠在鑰匙串中成功添加證書,但不能信任證書。 因此需要轉到KeyChain Access並手動信任證書。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.