ScMinidriver Chilkat2 Perl Reference Documentation

Chilkat2::ScMinidriver

Current Version: 11.7.0

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

Chilkat.ScMinidriver

Access smart-card certificates, key containers, PINs, files, and on-card signing.

Chilkat.ScMinidriver is a smart-card integration class for applications that need card minidriver access to certificates, key containers, PIN authentication, card files, and on-card signing. It can retrieve and link smart-card certificates for use in other Chilkat signing classes, generate or import RSA and ECC keys, sign data directly, inspect card and container state, and manage selected card files and certificates.

Connect through minidriver

Use the Windows smart-card minidriver layer to access card capabilities without working directly at the APDU level.

Certificates and containers

Enumerate and inspect smart-card certificates, key containers, container indexes, key types, and related card state.

PIN authentication

Authenticate to the card with the required PIN before accessing protected private-key operations or card objects.

On-card signing

Sign data using private keys that remain on the smart card, including workflows where the private key is non-exportable.

Key generation and import

Generate or import RSA and ECC keys into supported card containers when the card policy allows it.

Use with Chilkat signing

Link a smart-card certificate to other Chilkat classes so PDF, XML, CMS/PKCS7, S/MIME, or other signing operations can use the card-backed private key.

Common pattern: Connect to the smart card, verify the card and container state, authenticate with the PIN, locate the certificate and private-key container, then either sign directly or link the certificate for use by another Chilkat signing class. Use ScMinidriver for Windows card-minidriver certificate and key-container operations; use Chilkat.SCard for direct PC/SC APDU-level work, and Chilkat.Pkcs11 for PKCS#11 token or HSM sessions.

Object Creation

use Chilkat2;

my $scMinidriver = Chilkat2::ScMinidriver->new;
# or set properties (and RaiseError) at creation:
# my $scMinidriver = Chilkat2::ScMinidriver->new(VerboseLogging => 1, RaiseError => 1);
my $scMinidriver = Chilkat2::ScMinidriver->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/ScMinidriver.pm file holds only this class's documentation (perldoc Chilkat2::ScMinidriver). Windows only: the class exists only in the Windows builds of the module.

Perl frees the object when its last reference goes (undef $scMinidriver, 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::ScMinidriver';): an object is a blessed hash reference whose hash is free for the subclass's own fields.

my $boolVal = $scMinidriver->RaiseError;
$scMinidriver->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::ScMinidriver'), 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

Atr
# $strVal is a string (read-only)
my $strVal = $scMinidriver->Atr;
Introduced in version 9.5.0.87

The ATR of the card in the reader. This property is set by the AquireContext method.

top
CardName
# $strVal is a string (read-only)
my $strVal = $scMinidriver->CardName;
Introduced in version 9.5.0.87

The name of the card in the reader. This property is set by the AquireContext method.

top
DebugLogFilePath
# $strVal is a string
my $strVal = $scMinidriver->DebugLogFilePath;
$scMinidriver->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 = $scMinidriver->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 = $scMinidriver->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 = $scMinidriver->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 = $scMinidriver->LastMethodSuccess;
$scMinidriver->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
MaxContainers
# $intVal is an integer (read-only)
my $intVal = $scMinidriver->MaxContainers;
Introduced in version 9.5.0.87

The maximum number of key containers available. The 1st key container is at index 0. Each key container can potentially contain one signature key, and one key exchange key.

top
RsaPaddingHash
# $strVal is a string
my $strVal = $scMinidriver->RsaPaddingHash;
$scMinidriver->RsaPaddingHash($strVal);
Introduced in version 9.5.0.87

If an RSA key is used for signing, this is the hash algorithm to used in conjunction with the padding scheme. It can be SHA1, SHA256, SHA384, or SHA512. The default is SHA256.

top
RsaPaddingScheme
# $strVal is a string
my $strVal = $scMinidriver->RsaPaddingScheme;
$scMinidriver->RsaPaddingScheme($strVal);
Introduced in version 9.5.0.87

If an RSA key is used for signing, this is the padding scheme to use. It can be PKCS or PSS. The default is PSS.

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

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 = $scMinidriver->VerboseLogging;
$scMinidriver->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 = $scMinidriver->Version;

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

More Information and Examples
top

Methods

AcquireContext
# $readerName is a string
# $success is true or false
my $success = $scMinidriver->AcquireContext($readerName);
Introduced in version 9.5.0.87

Initializes communication with the card inserted in the given reader. Reader names can be discovered via the SCard.ListReaders or SCard.FindSmartcards methods. If successful, the Atr and CardName properties will be set.

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
CardDeleteFile
# $dirName is a string
# $fileName is a string
# $success is true or false
my $success = $scMinidriver->CardDeleteFile($dirName, $fileName);
Introduced in version 9.5.0.88

Deletes the file specified by $dirName and $fileName. $dirName is the name of the directory that contains the file, or the empty string for root.

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
DeleteCert
# $cert is a Chilkat2::Cert
# $delPrivKey is a boolean
# $success is true or false
my $success = $scMinidriver->DeleteCert($cert, $delPrivKey);
Introduced in version 9.5.0.88

Deletes a certificate and optionally its associated private key from the smart card. If $delPrivKey is 1, then the associated private key, if it exists, is also deleted.

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
DeleteContext
# $success is true or false
my $success = $scMinidriver->DeleteContext();
Introduced in version 9.5.0.87

This function reverses the effect of AcquireContext and severs the communication between the Base CSP/KSP and the card minidriver. The Atr and CardName properties are cleared.

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
DeleteKeyContainer
# $containerIndex is an integer
# $success is true or false
my $success = $scMinidriver->DeleteKeyContainer($containerIndex);
Introduced in version 9.5.0.87

Deletes the key container at the given $containerIndex. This deletes both the signature and key exchange keys that may be contained in the specified key container.

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
EnumFiles
# $dirName is a string
# $st is a Chilkat2::StringTable
# $success is true or false
my $success = $scMinidriver->EnumFiles($dirName, $st);
Introduced in version 9.5.0.87

Get the list of files in the directory specified by $dirName. Pass the empty string for the root directory. The filenames are returned in $st.

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
FindCert
# $certPart is a string
# $partValue is a string
# $cert is a Chilkat2::Cert
# $success is true or false
my $success = $scMinidriver->FindCert($certPart, $partValue, $cert);
Introduced in version 9.5.0.87

Finds the certificate where the given $certPart equals the $partValue. Possible values for $certPart are: subjectDN, subjectDN_withTags, subjectCN, serial, or serial:issuerCN.

The $cert is loaded with the certificate if successful.

Note: If successful, the $cert will be linked internally with this ScMinidriver session such that certificate can be used for signing on the smart card when used in other Chilkat classes such as XmlDSigGen, Pdf, Crypt2, Mime, MailMan, etc.

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
GenerateKey
# $containerIndex is an integer
# $keySpec is a string
# $keyType is a string
# $keySize is an integer
# $pinId is a string
# $success is true or false
my $success = $scMinidriver->GenerateKey($containerIndex, $keySpec, $keyType, $keySize, $pinId);
Introduced in version 9.5.0.87

Generates a key to be stored in either the signature or key exchange location within a key container. Creates the key container if it does not already exist. Otherwise replaces the key in the key container.

The $keySpec can be sig or kex to specify either the signature or key exchange location.

The $keyType can be ecc or rsa.

For RSA keys, the $keySize is the size of the key in bits, such as 1024, 2048, 4096, etc. (2048 is a typical value.) For ECC keys, the size can be 256, 384, or 521.

The $pinId can be user, or 3 through 7. (It is typically user.)

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
GetCardProperties
# $json is a Chilkat2::JsonObject
# $success is true or false
my $success = $scMinidriver->GetCardProperties($json);
Introduced in version 9.5.0.87

Gets all card properties and returns them in $json. See the example below.

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
GetCert
# $containerIndex is an integer
# $keySpec is a string
# $cert is a Chilkat2::Cert
# $success is true or false
my $success = $scMinidriver->GetCert($containerIndex, $keySpec, $cert);
Introduced in version 9.5.0.87

Get the certificate at the specified $containerIndex and $keySpec. The $keySpec can be sig or kex to specify either the signature or key exchange location within the container. The $containerIndex can be -1 to choose the first key container with a certificate. The $keySpec can also be any to choose either sig or kex based on which is present, with preference given to sig if both are present.

The $cert is loaded with the certificate if successful.

Note: If successful, the $cert will be linked internally with this ScMinidriver session such that certificate can be used for signing on the smart card when used in other Chilkat classes such as XmlDSigGen, Pdf, Crypt2, Mime, MailMan, etc.

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
GetContainerKeys
# $containerIndex is an integer
# $sigKey is a Chilkat2::PublicKey
# $kexKey is a Chilkat2::PublicKey
# $success is true or false
my $success = $scMinidriver->GetContainerKeys($containerIndex, $sigKey, $kexKey);
Introduced in version 9.5.0.87

Queries a key container to get the keys that are present. If the signature public key is present, it is returned in $sigKey. If the key exchange key is present, it is returned in $kexKey.

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
GetCspContainerMap
# $json is a Chilkat2::JsonObject
# $success is true or false
my $success = $scMinidriver->GetCspContainerMap($json);
Introduced in version 9.5.0.87

Returns the contents of the CSP container map file (cmapfile). The information is returned in the $json. This gives an overview of what key containers and certificates exist in the smart card from a CSP's point of view. See the example linked below.

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
ImportCert
# $cert is a Chilkat2::Cert
# $containerIndex is an integer
# $keySpec is a string
# $pinId is a string
# $success is true or false
my $success = $scMinidriver->ImportCert($cert, $containerIndex, $keySpec, $pinId);
Introduced in version 9.5.0.87

Imports a certificate with its private key onto the smart card. The $cert must have an accessible private key, such as will be the case if the $cert was loaded from a .pfx/.p12, or if the $cert was loaded from a Windows certificate store where the private key exists (and can be exported from the Windows certificate store).

The $containerIndex is the container index. It can range from 0 to the MaxContainers-1.

The $keySpec can be sig or kex to specify either the signature or key exchange location within the container.

The $pinId can be user, or 3 through 7. (It is typically user.)

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
ImportKey
# $containerIndex is an integer
# $keySpec is a string
# $privKey is a Chilkat2::PrivateKey
# $pinId is a string
# $success is true or false
my $success = $scMinidriver->ImportKey($containerIndex, $keySpec, $privKey, $pinId);
Introduced in version 9.5.0.87

Imports a key to be stored in either the signature or key exchange location within a key container. Creates the key container if it does not already exist. Otherwise replaces the specified key in the key container.

The $keySpec can be sig or kex to specify either the signature or key exchange location.

The $privKey is the private key to import.

The ARG5 can be user, or 3 through 7. (It is typically user.)

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
ListCerts
# $certPart is a string
# $st is a Chilkat2::StringTable
# $success is true or false
my $success = $scMinidriver->ListCerts($certPart, $st);
Introduced in version 9.5.0.87

Lists the certs found on the smart card. The $certPart indicates the information to be returned from each certificate. Possible values are: subjectDN, subjectDN_withTags, subjectCN, serial, or serial:issuerCN. The information is returned in $st.

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
PinAuthenticate
# $pinId is a string
# $pin is a string
# $n is an integer
my $n = $scMinidriver->PinAuthenticate($pinId, $pin);
Introduced in version 9.5.0.87

Performs regular PIN authentication. The $pinId can be user, admin, or 3 through 7. (It is typically user.) The $pin is the alphanumeric PIN.

Returns 0 for success. If not successful, the return value indicates the number of attempts remaining before the PIN is locked. (The number of times an incorrect PIN may be presented to the card before the PIN is blocked, and requires the admin to unblock it.) If the PIN is already blocked, the return value is -1. If the method fails for some other reason, such as if a context has not yet been acquired, the return value is -2.

top
PinAuthenticateHex
# $pinId is a string
# $pin is a string
# $n is an integer
my $n = $scMinidriver->PinAuthenticateHex($pinId, $pin);
Introduced in version 9.5.0.87

The same as PinAutheneticate, but the PIN is passed as a hex string. For example, to pass a PIN of 0x01, 0x02, 0x03, 0x04, pass 01020304.

top
PinChange
# $pinId is a string
# $currentPin is a string
# $newPin is a string
# $n is an integer
my $n = $scMinidriver->PinChange($pinId, $currentPin, $newPin);
Introduced in version 9.5.0.87

Changes a PIN. The $pinId can be user, admin, or 3 through 7. (It is typically user.) The $currentPin is the current alphanumeric PIN. The $newPin is the new PIN.

Returns 0 for success. If not successful, the return value indicates the number of attempts remaining before the PIN is locked. (The number of times an incorrect PIN may be presented to the card before the PIN is blocked, and requires the admin to unblock it.) If the PIN is already blocked, the return value is -1. If the method fails for some other reason, such as if a context has not yet been acquired, the return value is -2.

top
PinDeauthenticate
# $pinId is a string
# $success is true or false
my $success = $scMinidriver->PinDeauthenticate($pinId);
Introduced in version 9.5.0.87

Reverses a previous PIN authentication without resetting the card. The $pinId can be user, admin, or 3 through 7. (It is typically user.)

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
ReadFile
# $dirName is a string
# $fileName is a string
# $bd is a Chilkat2::BinData
# $success is true or false
my $success = $scMinidriver->ReadFile($dirName, $fileName, $bd);
Introduced in version 9.5.0.87

Reads the entire file specified by $dirName and $fileName into $bd. $dirName is the name of the directory that contains the file, or the empty string for root.

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
SignData
# $containerIndex is an integer
# $keySpec is a string
# $hashDataAlg is a string
# $bdData is a Chilkat2::BinData
# $bdSignedData is a Chilkat2::BinData
# $success is true or false
my $success = $scMinidriver->SignData($containerIndex, $keySpec, $hashDataAlg, $bdData, $bdSignedData);
Introduced in version 9.5.0.87

Signs the data passed in $bdData. The $hashDataAlg can be sha1, sha256, sha384, sha512, or none. If not equal to none, then the hash of the data passed in $bdData is signed.

The $containerIndex specifies the key container. By specifying the key container, you are almost specifying the key. A key container can contain two keys: A signature key, and a key-exchange key. The $keySpec indicates which of these two keys to use. $keySpec should be set to sig or kex.

Note: The type of signature created, such as RSA or ECC, is determined by the type of key that exists in the key container (specified by $containerIndex and $keySpec). If it is an RSA key, additional options can be specified via the RsaPaddingScheme and RsaPaddingHash properties.

If successful, the signature is written to $bdSignedData.

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
WriteFile
# $dirName is a string
# $fileName is a string
# $bd is a Chilkat2::BinData
# $success is true or false
my $success = $scMinidriver->WriteFile($dirName, $fileName, $bd);
Introduced in version 9.5.0.87

Writes the entire file specified by $dirName and $fileName. $dirName is the name of the directory that contains the file, or the empty string for root. The entire contents of $bd are written to the file on the smart card.

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