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
Use in-memory secrets when values should exist only for the lifetime of
the running process.
Store and retrieve secrets as strings, binary data, or structured JSON.
Start with the
Conceptual Overview
and
Components of a Secret Name.
For an extended overview, see the
Secrets Class Overview.
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
Cloud secret managers
Temporary secrets
Flexible content types
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);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.
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
my $boolVal = $secrets->AutoSplit;
$secrets->AutoSplit($boolVal);
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.
Compression
my $boolVal = $secrets->Compression;
$secrets->Compression($boolVal);
If set to 1, then the contents of the secret will be stored compressed. The default value of this property is 0.
DebugLogFilePath
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.
LastErrorHtml
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.
topLastErrorText
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.
LastErrorXml
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.
topLastMethodSuccess
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.
Location
my $strVal = $secrets->Location;
$secrets->Location($strVal);
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 Managerazure_key_vault- Azure Key Vaultibm_cloud- IBM Cloud Secrets Manageroracle_cloud- Oracle Cloud Secretsdoppler- Doppler Secretsmemory- In-Memory Secrets
The default location is the local_manager. On Linux and Android, local_manager will behave the same as memory.
UncommonOptions
my $strVal = $secrets->UncommonOptions;
$secrets->UncommonOptions($strVal);
This is a catch-all property to be used for uncommon needs. This property defaults to the empty string and should typically remain empty.
topVerboseLogging
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.
Version
my $strVal = $secrets->Version;
Methods
DeleteSecret
# $success is true or false
my $success = $secrets->DeleteSecret($jsonId);
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.
GetSecretBd
# $bd is a Chilkat2::BinData
# $success is true or false
my $success = $secrets->GetSecretBd($jsonId, $bd);
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.
GetSecretJson
# $jsonOut is a Chilkat2::JsonObject
# $success is true or false
my $success = $secrets->GetSecretJson($jsonId, $jsonOut);
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.
GetSecretSb
# $sb is a Chilkat2::StringBuilder
# $success is true or false
my $success = $secrets->GetSecretSb($jsonId, $sb);
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.
GetSecretStr
# $str is a string or undef
my $str = $secrets->GetSecretStr($jsonId);
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.
ListSecrets
# $jsonOut is a Chilkat2::JsonObject
# $success is true or false
my $success = $secrets->ListSecrets($json, $jsonOut);
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.
SecretSpecToJson
# $json is a Chilkat2::JsonObject
# $success is true or false
my $success = $secrets->SecretSpecToJson($secretSpec, $json);
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.
SetBootstrapSecret
# $secretContent is a Chilkat2::Secrets
# $success is true or false
my $success = $secrets->SetBootstrapSecret($jsonId, $secretContent);
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.
UpdateSecretBd
# $secret is a Chilkat2::BinData
# $success is true or false
my $success = $secrets->UpdateSecretBd($jsonId, $secret);
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.
UpdateSecretJson
# $secret is a Chilkat2::JsonObject
# $success is true or false
my $success = $secrets->UpdateSecretJson($jsonId, $secret);
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.
UpdateSecretSb
# $sb is a Chilkat2::StringBuilder
# $success is true or false
my $success = $secrets->UpdateSecretSb($jsonId, $sb);
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.
UpdateSecretStr
# $secret is a string
# $success is true or false
my $success = $secrets->UpdateSecretStr($jsonId, $secret);
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.
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" },
);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
$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.
Example
my $deadline = time() + 30; # give up after 30 seconds
$secrets->on(AbortCheck => sub { return time() > $deadline });PercentDone
$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.
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
});ProgressInfo
$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.
Example
$secrets->on(ProgressInfo => sub {
my ($name, $value) = @_;
print "$name: $value\n";
});