Я хочу получить сертификат с паролем из личного магазина с помощью Java-программирования.Я нашел некоторый код получения сертификата, но он показывает все сертификаты.Эти сертификаты показали, что данные не нужно открывать с этим связанным паролем.Я не хочу с этим стилем показывать сертификат.Я хочу написать тип формата кода - выберите сертификат, который я хочу, и я добавлю пароль этого сертификата в браузер, а затем покажу информацию о сертификате.
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null) ;
Enumeration en = ks.aliases() ;
while (en.hasMoreElements()) {
String aliasKey = (String)en.nextElement() ;
Certificate c = ks.getCertificate(aliasKey) ;
System.out.println("---> alias : " + aliasKey) ;
if (ks.isKeyEntry(aliasKey)) {
Certificate[] chain = ks.getCertificateChain(aliasKey);
System.out.println("---> chain length: " + chain.length);
X509Certificate Cert = null;
for (Certificate cert: chain) {
System.out.println(cert);
}
}
}
Как восстановить этот код?И я нашел код C # для доступа к сертификату.Я тоже хочу использовать Java-программу.Как преобразовать следующий код C # в код Java?
Сертификат доступа по C #
X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySerialNumber, "{serial number no space}", true);
//service is the webservice that need to //be authenticated using X509 certificate
TestWebService service = new TestWebService();
//Note, we should find the certificate from the the
//root certificate store on local machine if the
//certificate is imported correctly and the serial
//number is correct
if (col.Count == 1)
{
//all we need to do is to add the certificate
//after that we can use the webservice as usual
service.ClientCertificates.Add(col[0]);
service.Test();
}