Accessing Windows Certificate Store certs via Java? Accessing Windows Certificate Store certs via Java? windows windows

Accessing Windows Certificate Store certs via Java?


The cross-platform nature of the Java has its own downsides -- you cannot access some (or many) OS-specific things without external libraries. Windows certificate store is accessible only via CryptoAPI native functions which are not support by Java default installation.

You may take a look at this thread: Calling Win32 API method from Java

If you can use JNA, then you can use various Certificate and Certificate Store Functions in crypt32.dll to enumerate certificates and perform signing operations.


KeyStore keyStore = KeyStore.getInstance(getKeyStoreType(), "SunMSCAPI");keyStore.load(null, null);try {    Field field = keyStore.getClass().getDeclaredField("keyStoreSpi");    field.setAccessible(true);    KeyStoreSpi keyStoreVeritable = (KeyStoreSpi)field.get(keyStore);    field = keyStoreVeritable.getClass().getEnclosingClass().getDeclaredField("entries");    field.setAccessible(true);} catch (Exception e) {    LOGGER.log(Level.SEVERE, "Set accessible keyStoreSpi problem", e);}Enumeration enumeration = keyStore.aliases();