We're trying to use SunMSCAPI to retrieve a certificate from the Windows certificate store. I've created a very simple example that loads the keystore and lists the available aliases. However, the code doesn't list anything, even though I see two personal certificates in the keystore.
On my own system it works fine by the way, but on the actual application server we will be using it doesn't list anything.
Below is the code I'm using
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore ks = KeyStore.getInstance("Windows-MY");
ks.load(null, null);
Enumeration<String> aliases = ks.aliases();
System.out.println("Listing aliases " + ks.size());
while (aliases.hasMoreElements())
{
String ka = aliases.nextElement();
System.out.println(ka + " " + ks.isKeyEntry(ka));
}
And a screenshot of the certificate store on the application server. As you can see, I expected two aliases to be listed (but perhaps I'm looking in the wrong location?):
You are seeing the computer certificates, not user certificates. Windows-MY
keystore only can use the personal user certificates.
You can explore the personal certificates using Manage user certificates (certmgr
)from control panel instead of Manage computer certificates (certIm
)