TChilkatCert Delphi Reference

TChilkatCert

* This is a freeware class/component/library.

Digital certificate component / class

Object Creation

var
obj: TChilkatCert;
obj2: IChilkatCert;
...
begin
obj := TChilkatCert.Create(Self);
obj2 := TChilkatCert.Create(Self).ControlInterface;

Properties

property CspName: WideString readonly

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.

property Expired: Integer readonly

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.

property ForClientAuthentication: Integer readonly

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

property ForCodeSigning: Integer readonly

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

property ForSecureEmail: Integer readonly

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

property ForServerAuthentication: Integer readonly

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

property ForTimeStamping: Integer readonly

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

property HasKeyContainer: Integer readonly

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.

property IntendedKeyUsage: Integer readonly

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

property IsRoot: Integer readonly

1 if this is the root certificate, otherwise 0.

property IssuerC: WideString readonly

The certificate issuer's country.

property IssuerCN: WideString readonly

The certificate issuer's common name.

property IssuerDN: WideString readonly

The issuer's full distinguished name.

property IssuerE: WideString readonly

The certificate issuer's email address.

property IssuerL: WideString readonly

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

property IssuerO: WideString readonly

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

property IssuerOU: WideString readonly

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

property IssuerS: WideString readonly

The certificate issuer's state or province.

property KeyContainerName: WideString readonly

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.

property LastErrorHtml: WideString readonly

Error information in HTML format for the last method called.

property LastErrorText: WideString readonly

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

property LastErrorXml: WideString readonly

Error information in XML format for the last method called.

property MachineKeyset: Integer readonly

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.

property Revoked: Integer readonly

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).

property Rfc822Name: WideString readonly

The RFC-822 name of the certificate.

property SerialNumber: WideString readonly

The certificate's serial number.

property Sha1Thumbprint: WideString readonly

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

property SignatureVerified: Integer readonly

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.

property Silent: Integer readonly

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.

property SubjectC: WideString readonly

The certificate subject's country.

property SubjectCN: WideString readonly

The certificate subject's common name.

property SubjectDN: WideString readonly

The certificate subject's full distinguished name.

property SubjectE: WideString readonly

The certificate subject's email address.

property SubjectL: WideString readonly

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

property SubjectO: WideString readonly

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

property SubjectOU: WideString readonly

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

property SubjectS: WideString readonly

The certificate subject's state or province.

property TrustedRoot: Integer readonly

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

property ValidFrom: TDateTime readonly

The date this certificate becomes (or became) valid.

property ValidTo: TDateTime readonly

The date this certificate becomes (or became) invalid.

property Version: WideString readonly

The version of this component, such as "1.0"

Methods

function CheckRevoked(): Integer;

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

function ExportCertDer(): OleVariant;

Exports the digital certificate to ASN.1 DER format.

Returns 1 for success, 0 for failure.

function ExportCertDerFile(filename: WideString): Integer;

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

Returns 1 for success, 0 for failure.

function ExportCertPem(): WideString;

Exports the digital certificate to an unencrypted PEM formatted string.

Returns a null on failure

function ExportCertPemFile(filename: WideString): Integer;

Exports the digital certificate to an unencrypted PEM formatted file.

Returns 1 for success, 0 for failure.

function ExportPrivateKey(): TPrivateKey;

Exports the certificate's private key.

function ExportPublicKey(): TPublicKey;

Exports the certificate's public key.

function ExportToPfxFile(pfxFilename: WideString, password: WideString, includeChain: Integer): Integer;

To be documented soon...

function GetEncoded(): WideString;

Returns an encoded string representation of the certificate, which can be passed to SetFromEncoded to recreate the certificate object.

Returns a null on failure

function HasPrivateKey(): Integer;

Returns true if the private key is installed on the local system for the certificate. This information is not available when running on Windows 95/98 computers.

function IsExpired(): Integer;

Used to determine if the certificate is expired.

function LinkPrivateKey(keyContainerName: WideString, machineKeyset: Integer, forSigning: Integer): Integer;

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.

function LoadByCommonName(name: WideString): Integer;

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.

function LoadByEmailAddress(emailAddress: WideString): Integer;

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.

function LoadFromBase64(encodedCert: WideString): Integer;

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

function LoadFromBinary(binaryBlob: OleVariant): Integer;

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

function LoadFromFile(filename: WideString): Integer;

Loads a certificate from a .cer, .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.

function LoadPfxData(pfxData: OleVariant, password: WideString): Integer;

To be documented soon...

function LoadPfxFile(pfxFilename: WideString, password: WideString): Integer;

To be documented soon...

function PemFileToDerFile(pemFilename: WideString, derFilename: WideString): Integer;

Converts a PEM file to a DER file.

Returns 1 for success, 0 for failure.

procedure SaveLastError(filename: WideString);

Saves the last error information to an XML formatted file.

function SaveToFile(filename: WideString): Integer;

Saves a certificate object to a .cer file.

Returns 1 for success, 0 for failure.

function SetFromEncoded(encodedCert: WideString): Integer;

Initializes the certificate object from an encoded string created by the GetEncoded method.

procedure TestCert();

To be documented soon...