Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hablutzel1/0cb1e5260cce4b82675cd276bac40423 to your computer and use it in GitHub Desktop.
Save hablutzel1/0cb1e5260cce4b82675cd276bac40423 to your computer and use it in GitHub Desktop.
Load java.security.KeyStore with SunPKCS11 provider
import sun.security.pkcs11.SunPKCS11;
import java.security.KeyStore;
import java.security.Security;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
public class AccessingSmartCardThroughPKCS11 implements Test, Test2 {
public static void main(String[] args) throws Exception {
SunPKCS11 sunPKCS11 = new SunPKCS11("pkcs11.cfg");
Security.addProvider(sunPKCS11);
KeyStore pkcs11 = KeyStore.getInstance("PKCS11");
pkcs11.load(null, "secret".toCharArray());
Enumeration<String> aliases = pkcs11.aliases();
while (aliases.hasMoreElements()) {
String s = aliases.nextElement();
X509Certificate certificate = (X509Certificate) pkcs11.getCertificate(s);
System.out.println(certificate.getSubjectDN());
}
}
}
name = ePass2003
library = C:/Windows/System32/eps2003csp11.dll
slot=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment