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

Windows Credentials Manager / Apple Keychain - Get a String Secret

See more Secrets Examples

On Windows, fetches the content of a string secret from the Windows Credentials Manager.

On MacOS or iOS, fetches from the Apple Keychain.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local secrets = chilkat.Secrets.new()

-- On Windows, this is the Windows Credentials Manager
-- On MacOS/iOS, it is the Apple Keychain
secrets.location = "local_manager"

-- Specify the secret to be fetched.
local json = chilkat.JsonObject.new()
json:update_string("appName", "Test2")
json:update_string("service", "Something")
json:update_string("domain", "Xyz")
json:update_string("username", "Abc")

-- Get the secret.
local secretValue = secrets:get_secret_str(json)
if not secrets.last_method_success then
    print(secrets.last_error_text)
    return
end

print("The content of the secret: " .. secretValue)
print("Success.")