Java
Chilkat2 Java
Validate a Smartcard PIN
See more Certificates Examples
Validates a smartcard PIN. This example only runs on Windows and requires Chilkat v9.5.0.77 or greater.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.Cert;
import com.chilkatsoft.chilkat2.ChilkatException;
public class ChilkatExample {
public static void main(String[] args) {
// Note: Requires Chilkat v9.5.0.77 or greater.
Cert cert = new Cert();
cert.setSmartCardPin("000000");
// Load the certificate on the smartcard currently in the reader (or on the USB token).
// Pass an empty string to allow Chilkat to automatically choose the CSP (Cryptographi Service Provider).
// See Load Certificate on Smartcard for information about explicitly selecting a particular CSP.
try {
cert.loadFromSmartcard("");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Check to see if the SmartCardPin property contains the valid PIN for the smartcard.
int pinValid = cert.checkSmartCardPin();
if (pinValid < 0) {
System.out.println("Unable to check the PIN validity.");
System.out.println(cert.getLastErrorText());
return;
}
if (pinValid == 1) {
System.out.println("PIN is valid.");
} else {
System.out.println("PIN is invalid.");
}
}
}