CkCert Perl Programming
Reference Documentation

CkCert

* This is a freeware class/component/library.

Digital certificate component / class

Object Creation

$obj = new chilkat::CkCert();

Properties

# Returns a boolean value
get_AvoidWindowsPkAccess( )

# newVal is a boolean (input)
put_AvoidWindowsPkAccess( newVal )

Applies only when running on a Microsoft Windows operating system. If 1, then any method that returns a certificate will not try to also access the associated private key, assuming one exists. This is useful if the certificate was installed with high-security such that a private key access would trigger the Windows OS to display a security warning dialog. The default value of this property is 0.

# Returns an integer value
get_CertVersion( )

The version of the certificate (1, 2, or 3). A value of 0 indicates an error -- the most likely cause being that the certificate object is empty (i.e. was never loaded with a certificate). Note: This is not the version of the software, it is the version of the X.509 certificate object. The version of the Chilkat certificate software is indicated by the Version property.

# str is a CkString object (output)
get_CspName( str )

(Relevant only when running on a Microsoft Windows operating system.) If the HasKeyContainer property is 1, then the certificate is linked to a key container and this property contains the name of the associated CSP (cryptographic service provider). When a certificate is linked to a key container , the following properties will provide information about the key container and private key: CspName, KeyContainerName, MachineKeyset, and Silent.

# Returns a boolean value
get_Expired( )

Has a value of 1 if the certificate or any certificate in the chain of authority has expired. (This information is not available when running on Windows 95/98 computers.)

# Returns a boolean value
get_ForClientAuthentication( )

1 if this certificate can be used for client authentication, otherwise 0.

# Returns a boolean value
get_ForCodeSigning( )

1 if this certificate can be used for code signing, otherwise 0.

# Returns a boolean value
get_ForSecureEmail( )

1 if this certificate can be used for sending secure email, otherwise 0.

# Returns a boolean value
get_ForServerAuthentication( )

1 if this certificate can be used for server authentication, otherwise 0.

# Returns a boolean value
get_ForTimeStamping( )

1 if this certificate can be used for time stamping, otherwise 0.

# Returns a boolean value
get_HasKeyContainer( )

(Relevant only when running on a Microsoft Windows operating system.) Indicates whether this certificate is linked to a key container. If 1 then the certificate is linked to a key container (usually containing a private key). If 0, then it is not.

When a certificate is linked to a key container , the following properties will provide information about the key container and private key: CspName, KeyContainerName, MachineKeyset, and Silent.

# Returns an integer value
get_IntendedKeyUsage( )

Bitflags indicating the intended usages of the certificate. The flags are:
Digital Signature: 0x80
Non-Repudiation: 0x40
Key Encipherment: 0x20
Data Encipherment: 0x10
Key Agreement: 0x08
Certificate Signing: 0x04
CRL Signing: 0x02
Encipher-Only: 0x01

# Returns a boolean value
get_IsRoot( )

1 if this is the root certificate, otherwise 0.

# str is a CkString object (output)
get_IssuerC( str )

The certificate issuer's country.

# str is a CkString object (output)
get_IssuerCN( str )

The certificate issuer's common name.

# str is a CkString object (output)
get_IssuerDN( str )

The issuer's full distinguished name.

# str is a CkString object (output)
get_IssuerE( str )

The certificate issuer's email address.

# str is a CkString object (output)
get_IssuerL( str )

The certificate issuer's locality, which could be a city, count, township, or other geographic region.

# str is a CkString object (output)
get_IssuerO( str )

The certificate issuer's organization, which is typically the company name.

# str is a CkString object (output)
get_IssuerOU( str )

The certificate issuer's organizational unit, which is the unit within the organization.

# str is a CkString object (output)
get_IssuerS( str )

The certificate issuer's state or province.

# str is a CkString object (output)
get_KeyContainerName( str )

(Relevant only when running on a Microsoft Windows operating system.) If the HasKeyContainer property is 1, then the certificate is linked to a key container and this property contains the name of the key container.

When a certificate is linked to a key container , the following properties will provide information about the key container and private key: CspName, KeyContainerName, MachineKeyset, and Silent.

# str is a CkString object (output)
LastErrorHtml( str )

Error information in HTML format for the last method called.

# str is a CkString object (output)
LastErrorText( str )

Error information in plain-text format for the last method called.

# str is a CkString object (output)
LastErrorXml( str )

Error information in XML format for the last method called.

# Returns a boolean value
get_MachineKeyset( )

(Relevant only when running on a Microsoft Windows operating system.) If the HasKeyContainer property is 1, then the certificate is linked to a key container and this property indicates whether the key container is in the machine's keyset or in the keyset specific to the logged on user's account. If 1, the key container is within the machine keyset. If 0, it's in the user's keyset.

When a certificate is linked to a key container , the following properties will provide information about the key container and private key: CspName, KeyContainerName, MachineKeyset, and Silent.

# str is a CkString object (output)
get_OcspUrl( str )

To be documented soon...

# Returns a boolean value
get_PrivateKeyExportable( )

(Relevant only when running on a Microsoft Windows operating system.) Indicates whether the private key was installed with security settings that allow it to be re-exported.

# Returns a boolean value
get_Revoked( )

1 if the certificate or any certificate in the chain of authority has been revoked. This information is not available when running on Windows 95/98 computers. Note: If this property is 0, it could mean that it was not able to check the revocation status. Because of this uncertainty, a CheckRevoked method has been added. It returns an integer indicating one of three possible states: 1 (revoked) , 0 (not revoked), -1 (unable to check revocation status).

# str is a CkString object (output)
get_Rfc822Name( str )

The RFC-822 name of the certificate. (Also known as the Subject Alternative Name.)

# Returns a boolean value
get_SelfSigned( )

1 if this is a self-signed certificate, otherwise 0.

# str is a CkString object (output)
get_SerialNumber( str )

The certificate's serial number as a hexidecimal string.

# str is a CkString object (output)
get_Sha1Thumbprint( str )

Hexidecimal string of the SHA-1 thumbprint for the certificate.

# Returns a boolean value
get_SignatureVerified( )

True if the certificate and all certificates in the chain of authority have valid signatures. This information is not available when running on Windows 95/98 computers.

# Returns a boolean value
get_Silent( )

(Relevant only when running on a Microsoft Windows operating system.) If the HasKeyContainer property is 1, then the certificate is linked to a key container and this property indicates whether accessing the private key will cause the operating system to launch an interactive warning dialog. If 0 a warning dialog will be displayed. If 1 then private key accesses are silent.

When a certificate is linked to a key container , the following properties will provide information about the key container and private key: CspName, KeyContainerName, MachineKeyset, and Silent.

# str is a CkString object (output)
get_SubjectC( str )

The certificate subject's country.

# str is a CkString object (output)
get_SubjectCN( str )

The certificate subject's common name.

# str is a CkString object (output)
get_SubjectDN( str )

The certificate subject's full distinguished name.

# str is a CkString object (output)
get_SubjectE( str )

The certificate subject's email address.

# str is a CkString object (output)
get_SubjectL( str )

The certificate subject's locality, which could be a city, count, township, or other geographic region.

# str is a CkString object (output)
get_SubjectO( str )

The certificate subject's organization, which is typically the company name.

# str is a CkString object (output)
get_SubjectOU( str )

The certificate subject's organizational unit, which is the unit within the organization.

# str is a CkString object (output)
get_SubjectS( str )

The certificate subject's state or province.

# Returns a boolean value
get_TrustedRoot( )

True if the certificate has a trusted root authority. This information is not available when running on Windows 95/98 computers.

# Returns a boolean value
get_Utf8( )

# b is a boolean (input)
put_Utf8( b )

When set to true, all "const char *" arguments are expected to be utf-8 strings. If set to false, the "const char *" arguments are expected to be ANSI strings.

# sysTime is a SYSTEMTIME object (output)
get_ValidFrom( sysTime )

The date this certificate becomes (or became) valid.

More information about using SYSTEMTIME in Perl

# sysTime is a SYSTEMTIME object (output)
get_ValidTo( sysTime )

The date this certificate becomes (or became) invalid.

More information about using SYSTEMTIME in Perl

# Returns a boolean value
get_VerboseLogging( )

# newVal is a boolean (input)
put_VerboseLogging( newVal )

To be documented soon...

# str is a CkString object (output)
get_Version( str )

The version of this component, such as "1.0"

Methods

# Returns an integer value
CheckRevoked( )

Returns 1 if the certificate has been revoked, 0 if not revoked, and -1 if unable to check the revocation status.

# data is a CkByteData object (output)
# Returns a boolean value
ExportCertDer( data )

Exports the digital certificate to ASN.1 DER format.

# filename is a string (input)
# Returns a boolean value
ExportCertDerFile( filename )

Exports the digital certificate to ASN.1 DER format binary file.

Returns 1 for success, 0 for failure.

# str is a CkString object (output)
# Returns a boolean value
ExportCertPem( str )

Exports the digital certificate to an unencrypted PEM formatted string.

Returns 1 for success, 0 for failure.

# filename is a string (input)
# Returns a boolean value
ExportCertPemFile( filename )

Exports the digital certificate to an unencrypted PEM formatted file.

Returns 1 for success, 0 for failure.

# outStr is a CkString object (output)
# Returns a boolean value
ExportCertXml( outStr )

To be documented soon...

ExportPrivateKey( )

Exports the certificate's private key.

ExportPublicKey( )

Exports the certificate's public key.

# pfxFilename is a string (input)
# pfxPassword is a string (input)
# bIncludeCertChain is a boolean (input)
# Returns a boolean value
ExportToPfxFile( pfxFilename, pfxPassword, bIncludeCertChain )

Exports the certificate and private key (if available) to a PFX (.pfx or .p12) file. The output PFX is secured using the pfxPassword. If bIncludeCertChain is 1, then the certificates in the chain of authority are also included in the PFX output file.

Returns 1 for success, 0 for failure.

# Returns a CkCert object
FindIssuer( )

To be documented soon...

# str is a CkString object (output)
# Returns a boolean value
GetEncoded( str )

Returns a base64 encoded string representation of the certificate's binary DER format, which can be passed to SetFromEncoded to recreate the certificate object.

Returns 1 for success, 0 for failure.

# outStr is a CkString object (output)
# Returns a boolean value
GetPrivateKeyPem( outStr )

Exports the certificate's private key to a PEM string (if the private key is available).

Returns 1 for success, 0 for failure.

# Returns a boolean value
HasPrivateKey( )

Returns true if the private key is installed on the local system for the certificate.

# keyContainerName is a string (input)
# bMachineKeyset is a boolean (input)
# bForSigning is a boolean (input)
# Returns a boolean value
LinkPrivateKey( keyContainerName, bMachineKeyset, bForSigning )

(Relevant only when running on a Microsoft Windows operating system.) Associates a private key with a certificate. The private key is specified by providing the name of the key container where it can be found. The 2nd argument indicates whether the key container is from the machine-wide keyset (1), or from the keyset specific to the logged-on user (0). Private keys can be imported into a key container by calling the KeyContainer's ImportPrivateKey method. Once a certificate has been linked, the private key is available for creating digital signatures or decrypting. Note: Certificates imported from a PFX or from a Certificate Authority will already be "linked" and it is not necessary to call this method.

Returns 1 for success, 0 for failure.

# cn is a string (input)
# Returns a boolean value
LoadByCommonName( cn )

(Relevant only when running on a Microsoft Windows operating system.) Searches the Windows Local Machine and Current User registry-based certificate stores for a certificate having the common name specified. If found, the certificate is loaded and ready for use.

Returns 1 for success, 0 for failure.

Select Cert for Encrypted Email

# emailAddress is a string (input)
# Returns a boolean value
LoadByEmailAddress( emailAddress )

(Relevant only when running on a Microsoft Windows operating system.) Searches the Windows Local Machine and Current User registry-based certificate stores for a certificate containing the email address specified. If found, the certificate is loaded and ready for use.

Returns 1 for success, 0 for failure.

Select Cert for Encrypted Email

# issuerCN is a string (input)
# serialNumber is a string (input)
# Returns a boolean value
LoadByIssuerAndSerialNumber( issuerCN, serialNumber )

(Relevant only when running on a Microsoft Windows operating system.) Searches the Windows Local Machine and Current User registry-based certificate stores for a certificate matching the issuerCN and having an issuer matching the serialNumber. If found, the certificate is loaded and ready for use.

Returns 1 for success, 0 for failure.

# encodedCert is a string (input)
# Returns a boolean value
LoadFromBase64( encodedCert )

Loads an ASN.1 or DER encoded certificate represented in a Base64 string.

Returns 1 for success, 0 for failure.

# buf is a string (input)
# bufLen is an integer (input)
# Returns a boolean value
LoadFromBinary( buf, bufLen )

Loads an ASN.1 or DER encoded certificate represented as a binary blob.

Returns 1 for success, 0 for failure.

# filename is a string (input)
# Returns a boolean value
LoadFromFile( filename )

Loads a certificate from a .cer, .crt, .p7b, or .pem file. This method accepts certificates from files in any of the following formats:
1. DER encoded binary X.509 (.CER)
2. Base-64 encoded X.509 (.CER)
3. Cryptographic Message Syntax Standard - PKCS #7 Certificates (.P7B)
4. PEM format
This method decodes the certificate based on the contents if finds within the file, and not based on the file extension. If your certificate is in a file having a different extension, try loading it using this method before assuming it won't work. This method does not load .p12 or .pfx (PKCS #12) files.

Returns 1 for success, 0 for failure.

# pfxData is a CkByteData object (output)
# password is a string (input)
# Returns a boolean value
LoadPfxData( pfxData, password )

Loads a PFX from an in-memory image of a PFX file. Note: If the PFX contains multiple certificates, the 1st certificate in the PFX is loaded.

Returns 1 for success, 0 for failure.

# buf is a byte array (input)
# bufLen is an integer (input)
# password is a string (input)
# Returns a boolean value
LoadPfxData2( buf, bufLen, password )

Loads a PFX from an in-memory image of a PFX file. Note: If the PFX contains multiple certificates, the 1st certificate in the PFX is loaded.

Returns 1 for success, 0 for failure.

# filename is a string (input)
# password is a string (input)
# Returns a boolean value
LoadPfxFile( filename, password )

Loads a PFX file. Note: If the PFX contains multiple certificates, the 1st certificate in the PFX is loaded.

Returns 1 for success, 0 for failure.

# inFilename is a string (input)
# outFilename is a string (input)
# Returns a boolean value
PemFileToDerFile( inFilename, outFilename )

Converts a PEM file to a DER file.

Returns 1 for success, 0 for failure.

# filename is a string (input)
# Returns a boolean value
SaveLastError( filename )

Saves the last error information to an XML formatted file.

# filename is a string (input)
# Returns a boolean value
SaveToFile( filename )

Saves a certificate object to a .cer file.

Returns 1 for success, 0 for failure.

# encodedCert is a string (input)
# Returns a boolean value
SetFromEncoded( encodedCert )

Initializes the certificate object from a base64 encoded string representation of the certificate's binary DER format.

Returns 1 for success, 0 for failure.

# Returns a boolean value
SetPrivateKey( privKey )

Used to associate a private key with the certificate for subsequent (PKCS7) signature creation or decryption.

Returns 1 for success, 0 for failure.

# privKeyPem is a string (input)
# Returns a boolean value
SetPrivateKeyPem( privKeyPem )

Same as SetPrivateKey, but the key is provided in unencrypted PEM format. (Note: The privKeyPem is not a file path, it is the actual PEM text.)

Returns 1 for success, 0 for failure.

# Returns a string
cspName( )

(Relevant only when running on a Microsoft Windows operating system.) If the HasKeyContainer property is 1, then the certificate is linked to a key container and this property contains the name of the associated CSP (cryptographic service provider). When a certificate is linked to a key container , the following properties will provide information about the key container and private key: CspName, KeyContainerName, MachineKeyset, and Silent.

Returns a null on failure

# Returns a string
exportCertPem( )

Exports the digital certificate to an unencrypted PEM formatted string.

Returns a null on failure

# Returns a string
exportCertXml( )

To be documented soon...

# Returns a string
getEncoded( )

Returns a base64 encoded string representation of the certificate's binary DER format, which can be passed to SetFromEncoded to recreate the certificate object.

Returns a null on failure

# Returns a string
getPrivateKeyPem( )

Exports the certificate's private key to a PEM string (if the private key is available).

Returns a null on failure

# Returns a string
issuerC( )

The certificate issuer's country.

Returns a null on failure

# Returns a string
issuerCN( )

The certificate issuer's common name.

Returns a null on failure

# Returns a string
issuerDN( )

The issuer's full distinguished name.

Returns a null on failure

# Returns a string
issuerE( )

The certificate issuer's email address.

Returns a null on failure

# Returns a string
issuerL( )

The certificate issuer's locality, which could be a city, count, township, or other geographic region.

Returns a null on failure

# Returns a string
issuerO( )

The certificate issuer's organization, which is typically the company name.

Returns a null on failure

# Returns a string
issuerOU( )

The certificate issuer's organizational unit, which is the unit within the organization.

Returns a null on failure

# Returns a string
issuerS( )

The certificate issuer's state or province.

Returns a null on failure

# Returns a string
keyContainerName( )

(Relevant only when running on a Microsoft Windows operating system.) If the HasKeyContainer property is 1, then the certificate is linked to a key container and this property contains the name of the key container.

When a certificate is linked to a key container , the following properties will provide information about the key container and private key: CspName, KeyContainerName, MachineKeyset, and Silent.

Returns a null on failure

# Returns a string
lastErrorHtml( )

Error information in HTML format for the last method called.

Returns a null on failure

# Returns a string
lastErrorText( )

Error information in plain-text format for the last method called.

Returns a null on failure

# Returns a string
lastErrorXml( )

Error information in XML format for the last method called.

Returns a null on failure

# Returns a string
ocspUrl( )

To be documented soon...

# Returns a string
rfc822Name( )

The RFC-822 name of the certificate. (Also known as the Subject Alternative Name.)

Returns a null on failure

# Returns a string
serialNumber( )

The certificate's serial number as a hexidecimal string.

Returns a null on failure

# Returns a string
sha1Thumbprint( )

Hexidecimal string of the SHA-1 thumbprint for the certificate.

Returns a null on failure

# Returns a string
subjectC( )

The certificate subject's country.

Returns a null on failure

# Returns a string
subjectCN( )

The certificate subject's common name.

Returns a null on failure

# Returns a string
subjectDN( )

The certificate subject's full distinguished name.

Returns a null on failure

# Returns a string
subjectE( )

The certificate subject's email address.

Returns a null on failure

# Returns a string
subjectL( )

The certificate subject's locality, which could be a city, count, township, or other geographic region.

Returns a null on failure

# Returns a string
subjectO( )

The certificate subject's organization, which is typically the company name.

Returns a null on failure

# Returns a string
subjectOU( )

The certificate subject's organizational unit, which is the unit within the organization.

Returns a null on failure

# Returns a string
subjectS( )

The certificate subject's state or province.

Returns a null on failure

# Returns a string
version( )

The version of this component, such as "1.0"

Returns a null on failure