Lua Requires Chilkat v9.5.0.87+
Lua
Load Certificate from Smart Card by Serial Number
See more Certificates Examples
This example loads a certificate specified by its hexidecimal serial number. The LoadFromSmartcard method will examine the connected smart cards and USB tokens and will find and load the certificate having the specified serial number.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local cert = chilkat.Cert.new()
-- If you know the smart card PIN, set it prior to loading from the smartcard/USB token.
cert.smart_card_pin = "12345678"
-- To load the certificate specified by its hexidecimal serial number, pass the string "serial=<hexSerialNumber>". For example:
local success = cert:load_from_smartcard("serial=4A1E6ADCF59DB1EFBAAE438D2C52664E40D16A87")
if not success then
print(cert.last_error_text)
print("Certificate not loaded.")
return
end
print("Found: " .. cert.subject_dn .. " serial=" .. cert.serial_number)
-- Here's another example.
-- Note: serial numbers can be of different lengths. The length of the serial number depends on the certificate.
local cert2 = chilkat.Cert.new()
success = cert2:load_from_smartcard("serial=66BE58138D761E92BC594A722932657BE26D421F")
if not success then
print(cert2.last_error_text)
print("Certificate not loaded.")
return
end
print("Found: " .. cert2.subject_dn .. " serial=" .. cert2.serial_number)