Lua Requires Chilkat v10.1.2+
Lua
Open Smartcard Certificate Store (or from USB Token)
See more Certificates Examples
Demonstrates how to open the certificate store of the smart card currently in the reader (or the USB token). Iterates over the certs found on the smartcard.Chilkat Lua Downloads
local chilkat = require("chilkat")
local certStore = chilkat.CertStore.new()
-- Access the certificates on the smart card or USB token via the Chilkat certificate store class.
-- Note: Always pass the empty string to OpenSmartcard.
local success = certStore:open_smartcard("")
if not success then
print(certStore.last_error_text)
return
end
print(certStore.last_error_text)
-- Iterate over certificates on the smartcard.
local cert = chilkat.Cert.new()
local i = 0
local numCerts = certStore.num_certificates
print("numCerts = " .. numCerts)
while i < numCerts do
certStore:get_cert(i, cert)
print(cert.subject_cn)
print(cert.serial_number)
if cert:is_rsa() then
print("key type is RSA")
end
if cert:is_ecdsa() then
print("key type is ECDSA")
end
print("has private key: " .. tostring(cert:has_private_key()))
print("----")
i = i + 1
end