Sample code for 30+ languages & platforms
Lua Requires Chilkat v10.1.2+

Iterate over Certificates on Connected Smart Cards and USB Tokens

See more Cert Store Examples

Demonstrates how to iterate over the certificates on connected smart cards and USB tokens.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local certStore = chilkat.CertStore.new()

-- Detects connected smart cards and USB tokens
-- and loads the certificate store object with the certificates found.
-- Works on Windows, MacOS, iOS, and Linux.
-- Note: If something is not detected, contact info@chilkatsoft.com
-- for help or for workarounds.
local argNotUsed = ""
local success = certStore:open_smartcard(argNotUsed)
if not success then
    print(certStore.last_error_text)
    return
end

local cert = chilkat.Cert.new()

local numCerts = certStore.num_certificates
local i = 0

while i < numCerts do
    -- Load the cert object with the Nth certificate found in the connected HSMs
    certStore:get_cert(i, cert)
    print(i .. ": " .. cert.subject_cn)
    i = i + 1
end