Cert C Library Reference
Cert
* This is a freeware class/C library/library.
Digital certificate C library / class
Create/Dispose
HCkCert CkCert_Create(void);
Creates an instance of the CkCert object and returns a handle (i.e. a "void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.
void CkCert_Dispose(HCkCert handle);
Objects created by calling CkCert_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.
C "Properties"
void CkCert_getCspName(HCkCert cHandle, HCkString retval);
If the HasKeyContainer property is true, 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.
BOOL CkCert_getExpired(HCkCert cHandle);
Has a value of true 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.
BOOL CkCert_getForClientAuthentication(HCkCert cHandle);
true if this certificate can be used for client authentication, otherwise false.
BOOL CkCert_getForCodeSigning(HCkCert cHandle);
true if this certificate can be used for code signing, otherwise false.
BOOL CkCert_getForSecureEmail(HCkCert cHandle);
true if this certificate can be used for sending secure email, otherwise false.
BOOL CkCert_getForServerAuthentication(HCkCert cHandle);
true if this certificate can be used for server authentication, otherwise false.
BOOL CkCert_getForTimeStamping(HCkCert cHandle);
true if this certificate can be used for time stamping, otherwise false.
BOOL CkCert_getHasKeyContainer(HCkCert cHandle);
Indicates whether this certificate is linked to a key container. If true then the certificate is linked to a key container (usually containing a private key). If false, 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.
unsigned long CkCert_getIntendedKeyUsage(HCkCert cHandle);
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
BOOL CkCert_getIsRoot(HCkCert cHandle);
true if this is the root certificate, otherwise false.
void CkCert_getIssuerC(HCkCert cHandle, HCkString retval);
The certificate issuer's country.
void CkCert_getIssuerCN(HCkCert cHandle, HCkString retval);
The certificate issuer's common name.
void CkCert_getIssuerDN(HCkCert cHandle, HCkString retval);
The issuer's full distinguished name.
void CkCert_getIssuerE(HCkCert cHandle, HCkString retval);
The certificate issuer's email address.
void CkCert_getIssuerL(HCkCert cHandle, HCkString retval);
The certificate issuer's locality, which could be a city, count, township, or other geographic region.
void CkCert_getIssuerO(HCkCert cHandle, HCkString retval);
The certificate issuer's organization, which is typically the company name.
void CkCert_getIssuerOU(HCkCert cHandle, HCkString retval);
The certificate issuer's organizational unit, which is the unit within the organization.
void CkCert_getIssuerS(HCkCert cHandle, HCkString retval);
The certificate issuer's state or province.
void CkCert_getKeyContainerName(HCkCert cHandle, HCkString retval);
If the HasKeyContainer property is true, 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.
void CkCert_getLastErrorHtml(HCkCert cHandle, HCkString retval);
Error information in HTML format for the last method called.
void CkCert_getLastErrorText(HCkCert cHandle, HCkString retval);
Error information in plain-text format for the last method called.
void CkCert_getLastErrorXml(HCkCert cHandle, HCkString retval);
Error information in XML format for the last method called.
BOOL CkCert_getMachineKeyset(HCkCert cHandle);
If the HasKeyContainer property is true, 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 true, the key container is within the machine keyset. If false, 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.
BOOL CkCert_getRevoked(HCkCert cHandle);
true 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 false, 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).
void CkCert_getRfc822Name(HCkCert cHandle, HCkString retval);
The RFC-822 name of the certificate.
void CkCert_getSerialNumber(HCkCert cHandle, HCkString retval);
The certificate's serial number.
void CkCert_getSha1Thumbprint(HCkCert cHandle, HCkString retval);
Hexidecimal string of the SHA-1 thumbprint for the certificate.
BOOL CkCert_getSignatureVerified(HCkCert cHandle);
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.
BOOL CkCert_getSilent(HCkCert cHandle);
If the HasKeyContainer property is true, 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 false a warning dialog will be displayed. If true 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.
void CkCert_getSubjectC(HCkCert cHandle, HCkString retval);
The certificate subject's country.
void CkCert_getSubjectCN(HCkCert cHandle, HCkString retval);
The certificate subject's common name.
void CkCert_getSubjectDN(HCkCert cHandle, HCkString retval);
The certificate subject's full distinguished name.
void CkCert_getSubjectE(HCkCert cHandle, HCkString retval);
The certificate subject's email address.
void CkCert_getSubjectL(HCkCert cHandle, HCkString retval);
The certificate subject's locality, which could be a city, count, township, or other geographic region.
void CkCert_getSubjectO(HCkCert cHandle, HCkString retval);
The certificate subject's organization, which is typically the company name.
void CkCert_getSubjectOU(HCkCert cHandle, HCkString retval);
The certificate subject's organizational unit, which is the unit within the organization.
void CkCert_getSubjectS(HCkCert cHandle, HCkString retval);
The certificate subject's state or province.
BOOL CkCert_getTrustedRoot(HCkCert cHandle);
True if the certificate has a trusted root authority. This information is not available when running on Windows 95/98 computers.
BOOL CkCert_getUtf8(HCkCert cHandle); void CkCert_putUtf8(HCkCert cHandle, BOOL newVal);
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.
void CkCert_getValidFrom(HCkCert cHandle, SYSTEMTIME *retval);
The date this certificate becomes (or became) valid.
void CkCert_getValidTo(HCkCert cHandle, SYSTEMTIME *retval);
The date this certificate becomes (or became) invalid.
void CkCert_getVersion(HCkCert cHandle, HCkString retval);
The version of this component, such as "1.0"
C "Methods"
int CkCert_CheckRevoked(HCkCert cHandle);
Returns 1 if the certificate has been revoked, 0 if not revoked, and -1 if unable to check the revocation status.
BOOL CkCert_ExportCertDer(HCkCert cHandle, HCkByteData data);
Exports the digital certificate to ASN.1 DER format.
BOOL CkCert_ExportCertDerFile(HCkCert cHandle, const char *filename);
Exports the digital certificate to ASN.1 DER format binary file. Returns TRUE for success, FALSE for failure.
BOOL CkCert_ExportCertPem(HCkCert cHandle, HCkString str);
Exports the digital certificate to an unencrypted PEM formatted string.
BOOL CkCert_ExportCertPemFile(HCkCert cHandle, const char *filename);
Exports the digital certificate to an unencrypted PEM formatted file. Returns TRUE for success, FALSE for failure.
HCkPrivateKey CkCert_ExportPrivateKey(HCkCert cHandle);
Exports the certificate's private key.
HCkPublicKey CkCert_ExportPublicKey(HCkCert cHandle);
Exports the certificate's public key.
BOOL CkCert_ExportToPfxFile(HCkCert cHandle, const char *pfxFilename, const char *password, BOOL bIncludeChain);
To be documented soon...
BOOL CkCert_GetEncoded(HCkCert cHandle, HCkString str);
Returns an encoded string representation of the certificate, which can be passed to SetFromEncoded to recreate the certificate object.
BOOL CkCert_HasPrivateKey(HCkCert cHandle);
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.
BOOL CkCert_LinkPrivateKey(HCkCert cHandle, const char *keyContainerName, BOOL bMachineKeyset, BOOL bForSigning);
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 (true), or from the keyset specific to the logged-on user (false). 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 TRUE for success, FALSE for failure.
BOOL CkCert_LoadByCommonName(HCkCert cHandle, const char *cn);
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 TRUE for success, FALSE for failure.
BOOL CkCert_LoadByEmailAddress(HCkCert cHandle, const char *emailAddress);
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 TRUE for success, FALSE for failure.
BOOL CkCert_LoadFromBase64(HCkCert cHandle, const char *encodedCert);
Loads an ASN.1 or DER encoded certificate represented in a Base64 string.
BOOL CkCert_LoadFromBinary(HCkCert cHandle, const unsigned char *buf, unsigned long bufLen);
Loads an ASN.1 or DER encoded certificate represented as a binary blob.
BOOL CkCert_LoadFromFile(HCkCert cHandle, const char *filename);
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.
BOOL CkCert_LoadPfxData(HCkCert cHandle, HCkByteData pfxData, const char *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 TRUE for success, FALSE for failure.
BOOL CkCert_LoadPfxData2(HCkCert cHandle, const unsigned char *buf, unsigned long bufLen, const char *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 TRUE for success, FALSE for failure.
BOOL CkCert_LoadPfxFile(HCkCert cHandle, const char *filename, const char *password);
Loads a PFX file. Note: If the PFX contains multiple certificates, the 1st certificate in the PFX is loaded. Returns TRUE for success, FALSE for failure.
BOOL CkCert_PemFileToDerFile(HCkCert cHandle, const char *inFilename, const char *outFilename);
Converts a PEM file to a DER file. Returns TRUE for success, FALSE for failure.
BOOL CkCert_SaveLastError(HCkCert cHandle, const char *filename);
Saves the last error information to an XML formatted file.
BOOL CkCert_SaveToFile(HCkCert cHandle, const char *filename);
Saves a certificate object to a .cer file. Returns TRUE for success, FALSE for failure.
BOOL CkCert_SetFromEncoded(HCkCert cHandle, const char *encodedCert);
Initializes the certificate object from an encoded string created by the GetEncoded method.
void CkCert_TestCert(HCkCert cHandle);
To be documented soon...
const char *CkCert_cspName(HCkCert cHandle);
If the HasKeyContainer property is true, 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.
const char *CkCert_exportCertPem(HCkCert cHandle);
Exports the digital certificate to an unencrypted PEM formatted string.
const char *CkCert_getEncoded(HCkCert cHandle);
Returns an encoded string representation of the certificate, which can be passed to SetFromEncoded to recreate the certificate object.
const char *CkCert_issuerC(HCkCert cHandle);
The certificate issuer's country.
const char *CkCert_issuerCN(HCkCert cHandle);
The certificate issuer's common name.
const char *CkCert_issuerDN(HCkCert cHandle);
The issuer's full distinguished name.
const char *CkCert_issuerE(HCkCert cHandle);
The certificate issuer's email address.
const char *CkCert_issuerL(HCkCert cHandle);
The certificate issuer's locality, which could be a city, count, township, or other geographic region.
const char *CkCert_issuerO(HCkCert cHandle);
The certificate issuer's organization, which is typically the company name.
const char *CkCert_issuerOU(HCkCert cHandle);
The certificate issuer's organizational unit, which is the unit within the organization.
const char *CkCert_issuerS(HCkCert cHandle);
The certificate issuer's state or province.
const char *CkCert_keyContainerName(HCkCert cHandle);
If the HasKeyContainer property is true, 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.
const char *CkCert_lastErrorHtml(HCkCert cHandle);
Error information in HTML format for the last method called.
const char *CkCert_lastErrorText(HCkCert cHandle);
Error information in plain-text format for the last method called.
const char *CkCert_lastErrorXml(HCkCert cHandle);
Error information in XML format for the last method called.
const char *CkCert_rfc822Name(HCkCert cHandle);
The RFC-822 name of the certificate.
const char *CkCert_serialNumber(HCkCert cHandle);
The certificate's serial number.
const char *CkCert_sha1Thumbprint(HCkCert cHandle);
Hexidecimal string of the SHA-1 thumbprint for the certificate.
const char *CkCert_subjectC(HCkCert cHandle);
The certificate subject's country.
const char *CkCert_subjectCN(HCkCert cHandle);
The certificate subject's common name.
const char *CkCert_subjectDN(HCkCert cHandle);
The certificate subject's full distinguished name.
const char *CkCert_subjectE(HCkCert cHandle);
The certificate subject's email address.
const char *CkCert_subjectL(HCkCert cHandle);
The certificate subject's locality, which could be a city, count, township, or other geographic region.
const char *CkCert_subjectO(HCkCert cHandle);
The certificate subject's organization, which is typically the company name.
const char *CkCert_subjectOU(HCkCert cHandle);
The certificate subject's organizational unit, which is the unit within the organization.
const char *CkCert_subjectS(HCkCert cHandle);
The certificate subject's state or province.
const char *CkCert_version(HCkCert cHandle);
The version of this component, such as "1.0"
|