Sample code for 30+ languages & platforms
Lua

Import a Certificate (.cer file) into a Windows Certificate Store

See more Certificates Examples

Demonstrates how to import a certificate (without private key) into a Windows certificate store.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local cert = chilkat.Cert.new()

local success = cert:load_from_file("qa_data/certs/example.cer")
if not success then
    print(cert.last_error_text)
    return
end

local certStoreCU = chilkat.CertStore.new()
local readOnlyFlag = false

-- "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
success = certStoreCU:open_windows_store("CurrentUser", "My", readOnlyFlag)
if not success then
    print("Failed to open the CurrentUser/My certificate store for read/write.")
    return
end

-- Import the certificate into the CurrentUser/My certificate store.
success = certStoreCU:add_certificate(cert)
if not success then
    print(certStoreCU.last_error_text)
    return
end

print("Imported " .. cert.subject_cn)
print("Success.")