Created
May 2, 2020 21:19
-
-
Save hablutzel1/0cb1e5260cce4b82675cd276bac40423 to your computer and use it in GitHub Desktop.
Load java.security.KeyStore with SunPKCS11 provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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