Lua Requires Chilkat v9.5.0.87+
Lua
Load Certificate from Smart Card by Common Name
See more Certificates Examples
This example loads a certificate specified by its subject common name (CN part of the Subject). The LoadFromSmartcard method will examine the connected smart cards and USB tokens and will find and load the certificate having the specified CN.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 CN, pass the string "CN=<subjectCN>". For example:
local success = cert:load_from_smartcard("CN=Ch application signature (8c9be8e0-5544-4cd0-9062-290fbff353a7)")
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:
local cert2 = chilkat.Cert.new()
success = cert2:load_from_smartcard("CN=yubikey rsa 1024 authentication")
if not success then
print(cert2.last_error_text)
print("Certificate not loaded.")
return
end
print("Found: " .. cert2.subject_dn .. " serial=" .. cert2.serial_number)