Java
Chilkat2 Java
Load Certificate from Smartcard in Reader (or from USB Token)
See more Certificates Examples
Demonstrates how to load the certificate that is on the smartcard currently inserted into the smartcard reader. (Also can load the smartcard on a USB token.)Chilkat Java Downloads
import com.chilkatsoft.chilkat2.Cert;
import com.chilkatsoft.chilkat2.ChilkatException;
public class ChilkatExample {
public static void main(String[] args) {
Cert cert = new Cert();
// If you know the smart card PIN, set it prior to loading from the smartcard/USB token.
cert.setSmartCardPin("12345678");
// Pass an empty string to allow Chilkat to discover the smart card or USB token automatically.
try {
cert.loadFromSmartcard("");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Cert loaded from smartcard: " + cert.getSubjectCN());
}
}