ChilkatCert ActiveX Reference

ChilkatCert

* This is a freeware class/component/library.

Digital certificate component / class

Object Creation

(Visual Basic 6.0)
Dim obj As New ChilkatCert
(ASP)
set obj = Server.CreateObject("Chilkat.Cert")
(VBScript)
set obj = CreateObject("Chilkat.Cert")
(Delphi)
obj := TChilkatCert.Create(Self);
(FoxPro)
loObject = CreateObject('Chilkat.Cert')
(SQL Server)
EXEC @hr = sp_OACreate 'Chilkat.Cert', @obj OUT
(Javascript)
var obj = new ActiveXObject("Chilkat.Cert");

Properties

CspName As String (read-only)

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.

Expired As Long (read-only)

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.

ForClientAuthentication As Long (read-only)

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

ForCodeSigning As Long (read-only)

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

ForSecureEmail As Long (read-only)

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

ForServerAuthentication As Long (read-only)

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

ForTimeStamping As Long (read-only)

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

HasKeyContainer As Long (read-only)

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.

IntendedKeyUsage As Long (read-only)

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

IsRoot As Long (read-only)

1 if this is the root certificate, otherwise 0.

IssuerC As String (read-only)

The certificate issuer's country.

IssuerCN As String (read-only)

The certificate issuer's common name.

IssuerDN As String (read-only)

The issuer's full distinguished name.

IssuerE As String (read-only)

The certificate issuer's email address.

IssuerL As String (read-only)

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

IssuerO As String (read-only)

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

IssuerOU As String (read-only)

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

IssuerS As String (read-only)

The certificate issuer's state or province.

KeyContainerName As String (read-only)

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.

LastErrorHtml As String (read-only)

Error information in HTML format for the last method called.

LastErrorText As String (read-only)

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

LastErrorXml As String (read-only)

Error information in XML format for the last method called.

MachineKeyset As Long (read-only)

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.

Revoked As Long (read-only)

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

Rfc822Name As String (read-only)

The RFC-822 name of the certificate.

SerialNumber As String (read-only)

The certificate's serial number.

Sha1Thumbprint As String (read-only)

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

SignatureVerified As Long (read-only)

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.

Silent As Long (read-only)

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.

SubjectC As String (read-only)

The certificate subject's country.

SubjectCN As String (read-only)

The certificate subject's common name.

SubjectDN As String (read-only)

The certificate subject's full distinguished name.

SubjectE As String (read-only)

The certificate subject's email address.

SubjectL As String (read-only)

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

SubjectO As String (read-only)

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

SubjectOU As String (read-only)

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

SubjectS As String (read-only)

The certificate subject's state or province.

TrustedRoot As Long (read-only)

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

ValidFrom As Date (read-only)

The date this certificate becomes (or became) valid.

ValidTo As Date (read-only)

The date this certificate becomes (or became) invalid.

Version As String (read-only)

The version of this component, such as "1.0"

Methods

CheckRevoked() As Long

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

ExportCertDer() As Variant

Exports the digital certificate to ASN.1 DER format.

Returns a Variant containing the certificate as a DER-encoded byte array.

Returns a zero-length byte array (as a Variant) on failure

ExportCertDerFile(filename As String) As Long

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

Returns 1 for success, 0 for failure.

ExportCertPem() As String

Exports the digital certificate to an unencrypted PEM formatted string.

Returns a null on failure

ExportCertPemFile(filename As String) As Long

Exports the digital certificate to an unencrypted PEM formatted file.

Returns 1 for success, 0 for failure.

ExportPrivateKey() As PrivateKey

Exports the certificate's private key.

Returns a PrivateKey object if successful. Otherwise returns null.

ExportPublicKey() As PublicKey

Exports the certificate's public key.

Returns a PublicKey object if successful. Otherwise returns null.

ExportToPfxFile(pfxFilename As String, password As String, includeChain As Long) As Long

To be documented soon...

GetEncoded() As String

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

Returns a null on failure

HasPrivateKey() As Long

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.

IsExpired() As Long

Used to determine if the certificate is expired.

1 = expired, 0 = not expired.

LinkPrivateKey(keyContainerName As String, machineKeyset As Long, forSigning As Long) As Long

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.

LoadByCommonName(name As String) As Long

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.

(ASP) Select Cert for Encrypted Email

(VB6) Select Cert for Encrypted Email

(Delphi) Select Cert for Encrypted Email

(FoxPro) Select Cert for Encrypted Email

(VBScript) Select Cert for Encrypted Email

LoadByEmailAddress(emailAddress As String) As Long

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.

(ASP) Select Cert for Encrypted Email

(VB6) Select Cert for Encrypted Email

(Delphi) Select Cert for Encrypted Email

(FoxPro) Select Cert for Encrypted Email

(VBScript) Select Cert for Encrypted Email

LoadFromBase64(encodedCert As String) As Long

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

LoadFromBinary(binaryBlob As Variant) As Long

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

LoadFromFile(filename As String) As Long

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.

LoadPfxData(pfxData As Variant, password As String) As Long

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.

LoadPfxFile(pfxFilename As String, password As String) As Long

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.

PemFileToDerFile(pemFilename As String, derFilename As String) As Long

Converts a PEM file to a DER file.

Returns 1 for success, 0 for failure.

SaveLastError(filename As String)

Saves the last error information to an XML formatted file.

SaveToFile(filename As String) As Long

Saves a certificate object to a .cer file.

Returns 1 for success, 0 for failure.

SetFromEncoded(encodedCert As String) As Long

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

TestCert()

To be documented soon...