Secrets Chilkat2 Perl Reference Documentation

Chilkat2::Secrets

Current Version: 11.7.0

Markdown version of this page for AI tools (v 11.7.0) · all AI docs

Chilkat.Secrets

Manage application secrets through one consistent API.

Chilkat.Secrets provides a unified interface for storing, retrieving, listing, and deleting secrets across local, cloud-based, and in-memory secret stores. It supports string, binary, and JSON secrets, making it useful for passwords, API keys, OAuth credentials, tokens, unlock codes, certificates, and private configuration data.

Local secure storage

  • Windows Credential Manager
  • Apple Keychain

Cloud secret managers

  • AWS Secrets Manager
  • Azure Key Vault
  • IBM Cloud Secrets Manager
  • Oracle Cloud Secrets
  • Doppler Secrets

Temporary secrets

Use in-memory secrets when values should exist only for the lifetime of the running process.

Flexible content types

Store and retrieve secrets as strings, binary data, or structured JSON.

Note: Cloud-based secret managers often require local bootstrap credentials. These can be stored securely in the Windows Credential Manager or Apple Keychain and then used to authenticate to the cloud secret manager.

Object Creation

use Chilkat2;

my $secrets = Chilkat2::Secrets->new;
# or set properties (and RaiseError) at creation:
# my $secrets = Chilkat2::Secrets->new(VerboseLogging => 1, RaiseError => 1);
my $secrets = Chilkat2::Secrets->new(Property => $value, ...);

Creates the object. The optional pairs set writable properties (and RaiseError) in order, as if set one by one; an unknown or read-only name croaks. use Chilkat2; loads every class; the Chilkat2/Secrets.pm file holds only this class's documentation (perldoc Chilkat2::Secrets).

Perl frees the object when its last reference goes (undef $secrets, or the variable going out of scope); there is nothing to close. Objects returned by methods are independent and freed the same way. The class may be subclassed (use parent -norequire, 'Chilkat2::Secrets';): an object is a blessed hash reference whose hash is free for the subclass's own fields.

my $boolVal = $secrets->RaiseError;
$secrets->RaiseError($boolVal);

When false (the default), a method that fails returns false (or undef), and the reason is in LastErrorText. When true, it dies with a Chilkat2::Error instead, as DBI does with its RaiseError. Objects returned by a method inherit the value of the object that returned them.

Errors

A Chilkat2::Error stringifies to the failed call's full LastErrorText, and has the methods text, class ('Chilkat2::Secrets'), method (the method name) and object. Methods that look something up and find nothing return undef without dying (each such method says so), methods that answer a question (HasMember, IsUnlocked, ...) return a plain boolean, and property reads and writes never fail for Chilkat reasons.

Misuse always croaks, with your file and line, whatever RaiseError is: a wrong number of arguments, a reference or undef where a string or number is expected, an object of the wrong class, an out-of-range integer, a string containing a NUL character, a wide character in a byte string, or a write to a read-only property.

Strings are Perl character strings in both directions (length, regexes and :encoding layers see characters); binary data (BinData) is a byte string. Unlocking: call Chilkat2::Global->new->UnlockBundle('...') once at startup.

Properties

AutoSplit
# $boolVal is a boolean
my $boolVal = $secrets->AutoSplit;
$secrets->AutoSplit($boolVal);
Introduced in version 10.1.0

The AutoSplit property is specific to local_manager secrets on Windows. The Windows Credentials Manager supports a maximum of 2560 bytes per secret. If a secret exceeds this size, it will be automatically compressed and split when created or updated, and automatically recomposed when retrieved.

A secret can be split into a maximum of 10 parts.

The default value is 1.

top
Compression
# $boolVal is a boolean
my $boolVal = $secrets->Compression;
$secrets->Compression($boolVal);
Introduced in version 10.1.0

If set to 1, then the contents of the secret will be stored compressed. The default value of this property is 0.

top
DebugLogFilePath
# $strVal is a string
my $strVal = $secrets->DebugLogFilePath;
$secrets->DebugLogFilePath($strVal);

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
LastErrorHtml
# $strVal is a string (read-only)
my $strVal = $secrets->LastErrorHtml;

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
# $strVal is a string (read-only)
my $strVal = $secrets->LastErrorText;

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
# $strVal is a string (read-only)
my $strVal = $secrets->LastErrorXml;

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
# $boolVal is a boolean
my $boolVal = $secrets->LastMethodSuccess;
$secrets->LastMethodSuccess($boolVal);

Indicates the success or failure of the most recent method call: 1 means success, 0 means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
Location
# $strVal is a string
my $strVal = $secrets->Location;
$secrets->Location($strVal);
Introduced in version 10.1.0

The location of the secrets. Possible values are:

  • local_manager - On Windows this is the Credentials Manager. On MacOS and iOS it is the Keychain. This is not yet an option on Linux or Android.
  • aws_secrets_manager - AWS Secrets Manager
  • azure_key_vault - Azure Key Vault
  • ibm_cloud - IBM Cloud Secrets Manager
  • oracle_cloud - Oracle Cloud Secrets
  • doppler - Doppler Secrets
  • memory - In-Memory Secrets

The default location is the local_manager. On Linux and Android, local_manager will behave the same as memory.

top
UncommonOptions
# $strVal is a string
my $strVal = $secrets->UncommonOptions;
$secrets->UncommonOptions($strVal);
Introduced in version 10.1.0

This is a catch-all property to be used for uncommon needs. This property defaults to the empty string and should typically remain empty.

top
VerboseLogging
# $boolVal is a boolean
my $boolVal = $secrets->VerboseLogging;
$secrets->VerboseLogging($boolVal);

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
# $strVal is a string (read-only)
my $strVal = $secrets->Version;

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

DeleteSecret
# $jsonId is a Chilkat2::JsonObject
# $success is true or false
my $success = $secrets->DeleteSecret($jsonId);
Introduced in version 10.1.0

Deletes a secret. Cloud secrets managers will typically disable the secret and schedule the secret for deletion after some number of days.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GetSecretBd
# $jsonId is a Chilkat2::JsonObject
# $bd is a Chilkat2::BinData
# $success is true or false
my $success = $secrets->GetSecretBd($jsonId, $bd);
Introduced in version 10.1.0

Fetches a binary secret and returns the content in $bd.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GetSecretJson
# $jsonId is a Chilkat2::JsonObject
# $jsonOut is a Chilkat2::JsonObject
# $success is true or false
my $success = $secrets->GetSecretJson($jsonId, $jsonOut);
Introduced in version 10.1.0

Fetches a JSON secret and returns the content in $jsonOut.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GetSecretSb
# $jsonId is a Chilkat2::JsonObject
# $sb is a Chilkat2::StringBuilder
# $success is true or false
my $success = $secrets->GetSecretSb($jsonId, $sb);
Introduced in version 10.1.0

Fetches a string secret and returns the content in $sb.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
GetSecretStr
# $jsonId is a Chilkat2::JsonObject
# $str is a string or undef
my $str = $secrets->GetSecretStr($jsonId);
Introduced in version 10.1.0

Fetches a string secret and returns the content of the secret.

Returns undef on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
ListSecrets
# $json is a Chilkat2::JsonObject
# $jsonOut is a Chilkat2::JsonObject
# $success is true or false
my $success = $secrets->ListSecrets($json, $jsonOut);
Introduced in version 10.1.0

Lists secrets matching the wildcarded or exact values passed in $json. The results of the query are returned in $jsonOut.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
SecretSpecToJson
# $secretSpec is a string
# $json is a Chilkat2::JsonObject
# $success is true or false
my $success = $secrets->SecretSpecToJson($secretSpec, $json);
Introduced in version 11.5.0

Converts a secret specification string ($secretSpec) to JSON. A secret specification string is formatted as "!!part1|part2|part3|part4" where parts 3 and 4 are optional. $json is the output argument.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

More Information and Examples
top
SetBootstrapSecret
# $jsonId is a Chilkat2::JsonObject
# $secretContent is a Chilkat2::Secrets
# $success is true or false
my $success = $secrets->SetBootstrapSecret($jsonId, $secretContent);
Introduced in version 10.1.0

Accessing a cloud-based secrets manager requires authentication credentials, which cannot be stored in the manager itself. Instead, they must be securely stored locally.

One solution is to store the authentication credentials as a secret in the Windows Credentials Manager or Apple Keychain. These credentials serve as the bootstrap secret for authenticating with the cloud-based secrets manager.

$jsonId contains the name of the bootstrap secret. $secretContent contains the bootstrap's secret content.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
UpdateSecretBd
# $jsonId is a Chilkat2::JsonObject
# $secret is a Chilkat2::BinData
# $success is true or false
my $success = $secrets->UpdateSecretBd($jsonId, $secret);
Introduced in version 10.1.0

Creates a binary secret if it does not yet exist, or updates an existing secret. The name of the secret is specified in $jsonId, and the binary content of the secret in $secret.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
UpdateSecretJson
# $jsonId is a Chilkat2::JsonObject
# $secret is a Chilkat2::JsonObject
# $success is true or false
my $success = $secrets->UpdateSecretJson($jsonId, $secret);
Introduced in version 10.1.0

Creates a JSON secret if it does not yet exist, or updates an existing secret. The name of the secret is specified in $jsonId, and the JSON content of the secret in $secret.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
UpdateSecretSb
# $jsonId is a Chilkat2::JsonObject
# $sb is a Chilkat2::StringBuilder
# $success is true or false
my $success = $secrets->UpdateSecretSb($jsonId, $sb);
Introduced in version 10.1.0

Creates a string secret if it does not yet exist, or updates an existing secret. The name of the secret is specified in $jsonId, and the string content of the secret in $sb.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top
UpdateSecretStr
# $jsonId is a Chilkat2::JsonObject
# $secret is a string
# $success is true or false
my $success = $secrets->UpdateSecretStr($jsonId, $secret);
Introduced in version 10.1.0

Creates a string secret if it does not yet exist, or updates an existing secret. The name of the secret is specified in $jsonId, and the string content of the secret in $secret.

Note: Starting in Chilkat v11.3.0, if the service = "Chilkat" and the username = "unlock_code", then the secret (which is the Chilkat unlock code) can be stored and retrieved without Chilkat being unlocked. This allows for the Chilkat unlock code itself to be persisted to a secrets manager.

Returns true on success, false on failure; LastErrorText says why. With RaiseError on, a failure dies with a Chilkat2::Error instead (it stringifies to the LastErrorText); the object remains usable either way.

top

Events

All Chilkat methods are synchronous: the call returns when the work is done. During a long-running call, Chilkat2::Secrets reports progress to handlers installed with on, which takes Event => CODE pairs (closures, so a handler can use the variables around it):

$secrets->on(
    PercentDone  => sub { my ($pctDone) = @_; print "$pctDone%\n"; return 0 },   # a true return aborts
    ProgressInfo => sub { my ($name, $value) = @_; print "$name: $value\n" },
);
$secrets->on(Event => CODE, ...);

Installs the handlers given, replacing those installed before for the same events; undef instead of a CODE reference removes one, and $secrets->on() with no arguments returns the installed handlers as a list of pairs. The event names are checked: a misspelled one croaks, and nothing is installed.

The AbortCheck handler is called periodically during long operations; PercentDone is called when an operation's completion percentage is known; ProgressInfo delivers named progress values. A true return from the AbortCheck or PercentDone handler aborts the running method, which then fails in the usual way (false or undef, or a Chilkat2::Error under RaiseError).

Handlers run during the method call, on the thread that called it. Inside a handler, other objects may be used, but calling a method of the same object (or its on) croaks. A die in a handler aborts the running method and is re-thrown from the method call; the object remains usable. A handler that uses $secrets itself makes a reference cycle: weaken the captured copy (Scalar::Util) or remove the handler when done.

AbortCheck
# handler: sub { ...; return $abort } -- a true return aborts the method in progress
$secrets->on(AbortCheck => sub { ... });

Enables a method call to be aborted by triggering the AbortCheck event at intervals defined by the HeartbeatMs property. If HeartbeatMs is set to its default value of 0, no events will occur. For instance, set HeartbeatMs to 200 to trigger 5 AbortCheck events per second.

More Information and Examples

Example

my $deadline = time() + 30;                          # give up after 30 seconds
$secrets->on(AbortCheck => sub { return time() > $deadline });
top
PercentDone
# handler: sub { my ($pctDone) = @_; ...; return $abort } -- a true return aborts
$secrets->on(PercentDone => sub { ... });

This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The pctDone argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have pctDone equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).

The PercentDone callback also acts as an AbortCheck event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.

To abort the operation, set the abort output argument to 1. This will cause the method to terminate and return a failure status or corresponding failure value.

More Information and Examples

Example

$secrets->on(PercentDone => sub {
    my ($pctDone) = @_;     # 0 to 100
    print "Percent done: $pctDone\n";
    return 0;               # return a true value to abort the method in progress
});
top
ProgressInfo
# handler: sub { my ($name, $value) = @_; ... }
$secrets->on(ProgressInfo => sub { ... });

This event callback provides tag name/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.

Note: Some Chilkat methods don't fire any ProgressInfo events.

More Information and Examples

Example

$secrets->on(ProgressInfo => sub {
    my ($name, $value) = @_;
    print "$name: $value\n";
});
top