Lua Requires Chilkat v10.1.0+
Lua
Windows Credentials Manager / Apple Keychain - List Matching Secrets
See more Secrets Examples
List secrets matching one or more wildcarded names for app, service, domain, and username.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 secrets = chilkat.Secrets.new()
-- On Windows, this is the Windows Credentials Manager
-- On MacOS/iOS, it is the Apple Keychain
secrets.location = "local_manager"
-- Set wildcarded or exact values for appName, service, domain, and username.
-- Omit any members where anything is allowed to match, or alternatively specify "*" to match anything.
local jsonMatch = chilkat.JsonObject.new()
jsonMatch:update_string("appName", "Test*")
jsonMatch:update_string("service", "*")
jsonMatch:update_string("domain", "*")
jsonMatch:update_string("username", "Starfish*")
local results = chilkat.JsonObject.new()
results.emit_compact = false
local success = secrets:list_secrets(jsonMatch, results)
if not success then
print(secrets.last_error_text)
return
end
print(results:emit())
-- Sample output on Windows.
-- The "targetName" is purely informational and indicates the raw TargetName of the secret (i.e. Credential) stored in the Credentials Manager.
-- {
-- "secrets": [
-- {
-- "appName": "Test2",
-- "service": "Custom",
-- "domain": "Ocean",
-- "username": "Starfish20",
-- "targetName": "Test2/Custom/Ocean/Starfish20"
-- },
-- {
-- "appName": "Test2",
-- "service": "Custom",
-- "domain": "Ocean",
-- "username": "Starfish",
-- "targetName": "Test2/Custom/Ocean/Starfish"
-- }
-- ]
-- }
-- ---------------------------------------------------------------------------------------
-- Here's sample code for parsing the JSON list of secrets.
local appName = ""
local service = ""
local domain = ""
local username = ""
local targetName = ""
local keyChainService = ""
local keyChainAccount = ""
local i = 0
local count_i = results:size_of_array("secrets")
while i < count_i do
results.i = i
appName = results:string_of("secrets[i].appName")
service = results:string_of("secrets[i].service")
domain = results:string_of("secrets[i].domain")
username = results:string_of("secrets[i].username")
-- Information field for Windows Credentials Manager.
targetName = results:string_of("secrets[i].targetName")
-- Informational fields if on MacOS using the Apple Keychain.
keyChainService = results:string_of("secrets[i].keyChainService")
keyChainAccount = results:string_of("secrets[i].keyChainAccount")
i = i + 1
end