(Java) Load Certificate from Smartcard in Reader (or from USB Token)
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.)
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
CkCert cert = new CkCert();
// If you know the smart card PIN, set it prior to loading from the smartcard/USB token.
cert.put_SmartCardPin("12345678");
// Pass an empty string to allow Chilkat to discover the smart card or USB token automatically.
boolean success = cert.LoadFromSmartcard("");
if (success == false) {
System.out.println(cert.lastErrorText());
return;
}
System.out.println("Cert loaded from smartcard: " + cert.subjectCN());
}
}
|