CkCert C++ Class Reference
CkCert
* This is a freeware class/component/library.
Digital certificate component / class
Properties
bool get_AvoidWindowsPkAccess(void); void put_AvoidWindowsPkAccess(bool newVal);
Applies only when running on a Microsoft Windows operating system. If true, 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 false.
int get_CertVersion(void);
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.
void get_CspName(CkString &str);
(Relevant only when running on a Microsoft Windows operating system.) 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 get_Expired(void);
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 get_ForClientAuthentication(void);
true if this certificate can be used for client authentication, otherwise false.
bool get_ForCodeSigning(void);
true if this certificate can be used for code signing, otherwise false.
bool get_ForSecureEmail(void);
true if this certificate can be used for sending secure email, otherwise false.
bool get_ForServerAuthentication(void);
true if this certificate can be used for server authentication, otherwise false.
bool get_ForTimeStamping(void);
true if this certificate can be used for time stamping, otherwise false.
bool get_HasKeyContainer(void);
(Relevant only when running on a Microsoft Windows operating system.) 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 get_IntendedKeyUsage(void);
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 get_IsRoot(void);
true if this is the root certificate, otherwise false.
void get_IssuerC(CkString &str);
The certificate issuer's country.
void get_IssuerCN(CkString &str);
The certificate issuer's common name.
void get_IssuerDN(CkString &str);
The issuer's full distinguished name.
void get_IssuerE(CkString &str);
The certificate issuer's email address.
void get_IssuerL(CkString &str);
The certificate issuer's locality, which could be a city, count, township, or other geographic region.
void get_IssuerO(CkString &str);
The certificate issuer's organization, which is typically the company name.
void get_IssuerOU(CkString &str);
The certificate issuer's organizational unit, which is the unit within the organization.
void get_IssuerS(CkString &str);
The certificate issuer's state or province.
void get_KeyContainerName(CkString &str);
(Relevant only when running on a Microsoft Windows operating system.) 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 LastErrorHtml(CkString &str);
Error information in HTML format for the last method called.
void LastErrorText(CkString &str);
Error information in plain-text format for the last method called.
void LastErrorXml(CkString &str);
Error information in XML format for the last method called.
bool get_MachineKeyset(void);
(Relevant only when running on a Microsoft Windows operating system.) 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.
void get_OcspUrl(CkString &str);
To be documented soon...
bool get_PrivateKeyExportable(void);
(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.
bool get_Revoked(void);
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 get_Rfc822Name(CkString &str);
The RFC-822 name of the certificate. (Also known as the Subject Alternative Name.)
bool get_SelfSigned(void);
true if this is a self-signed certificate, otherwise false.
void get_SerialNumber(CkString &str);
The certificate's serial number as a hexidecimal string.
void get_Sha1Thumbprint(CkString &str);
Hexidecimal string of the SHA-1 thumbprint for the certificate.
bool get_SignatureVerified(void);
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 get_Silent(void);
(Relevant only when running on a Microsoft Windows operating system.) 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 get_SubjectC(CkString &str);
The certificate subject's country.
void get_SubjectCN(CkString &str);
The certificate subject's common name.
void get_SubjectDN(CkString &str);
The certificate subject's full distinguished name.
void get_SubjectE(CkString &str);
The certificate subject's email address.
void get_SubjectL(CkString &str);
The certificate subject's locality, which could be a city, count, township, or other geographic region.
void get_SubjectO(CkString &str);
The certificate subject's organization, which is typically the company name.
void get_SubjectOU(CkString &str);
The certificate subject's organizational unit, which is the unit within the organization.
void get_SubjectS(CkString &str);
The certificate subject's state or province.
bool get_TrustedRoot(void);
True if the certificate has a trusted root authority. This information is not available when running on Windows 95/98 computers.
bool get_Utf8(void) const; void put_Utf8(bool 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.
void get_ValidFrom(SYSTEMTIME &sysTime);
The date this certificate becomes (or became) valid.
void get_ValidTo(SYSTEMTIME &sysTime);
The date this certificate becomes (or became) invalid.
bool get_VerboseLogging(void); void put_VerboseLogging(bool newVal);
To be documented soon...
void get_Version(CkString &str);
The version of this component, such as "1.0"
Methods
int CheckRevoked();
Returns 1 if the certificate has been revoked, 0 if not revoked, and -1 if unable to check the revocation status.
bool ExportCertDer(CkByteData & outData);
Exports the digital certificate to ASN.1 DER format. Writes the certificate as DER-encoded bytes into the CkByteData object.
bool ExportCertDerFile(const char * filename);
Exports the digital certificate to ASN.1 DER format binary file. Returns true for success, false for failure.
bool ExportCertPem(CkString & outStr);
Exports the digital certificate to an unencrypted PEM formatted string. Returns true for success, false for failure.
bool ExportCertPemFile(const char * filename);
Exports the digital certificate to an unencrypted PEM formatted file. Returns true for success, false for failure.
bool ExportCertXml(CkString & outStr);
To be documented soon...
CkPrivateKey * ExportPrivateKey();
Exports the certificate's private key. Returns a CkPrivateKey object if successful. Otherwise returns null.
CkPublicKey * ExportPublicKey();
Exports the certificate's public key. Returns a CkPublicKey object if successful. Otherwise returns null.
bool ExportToPfxFile(const char * pfxFilename, const char * pfxPassword, bool 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 true, then the certificates in the chain of authority are also included in the PFX output file. Returns true for success, false for failure.
CkCert * FindIssuer();
To be documented soon...
bool GetEncoded(CkString & outStr);
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 true for success, false for failure.
bool GetPrivateKeyPem(CkString & outStr);
Exports the certificate's private key to a PEM string (if the private key is available). Returns true for success, false for failure.
bool HasPrivateKey();
Returns true if the private key is installed on the local system for the certificate.
bool LinkPrivateKey(const char * keyContainerName, bool bMachineKeyset, bool 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 (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 LoadByCommonName(const char * 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 true for success, false for failure. Select Cert for Encrypted Email
bool LoadByEmailAddress(const char * 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 true for success, false for failure. Select Cert for Encrypted Email
bool LoadByIssuerAndSerialNumber(const char * issuerCN, const char * 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 true for success, false for failure.
bool LoadFromBase64(const char * encodedCert);
Loads an ASN.1 or DER encoded certificate represented in a Base64 string. Returns true for success, false for failure.
bool LoadFromBinary(const unsigned char * buf, unsigned long bufLen);
Loads an ASN.1 or DER encoded certificate represented as a binary blob. Returns true for success, false for failure.
bool LoadFromFile(const char * 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 true for success, false for failure.
bool LoadPfxData(CkByteData & 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 LoadPfxData2(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 LoadPfxFile(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 PemFileToDerFile(const char * inFilename, const char * outFilename);
Converts a PEM file to a DER file. Returns true for success, false for failure.
bool SaveLastError(const char * filename);
Saves the last error information to an XML formatted file.
bool SaveToFile(const char * filename);
Saves a certificate object to a .cer file. Returns true for success, false for failure.
bool SetFromEncoded(const char * encodedCert);
Initializes the certificate object from a base64 encoded string representation of the certificate's binary DER format. Returns true for success, false for failure.
bool SetPrivateKey(CkPrivateKey & privKey);
Used to associate a private key with the certificate for subsequent (PKCS7) signature creation or decryption. Returns true for success, false for failure.
bool SetPrivateKeyPem(const char * 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 true for success, false for failure.
const char * cspName();
(Relevant only when running on a Microsoft Windows operating system.) 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. Returns a null on failure
const char * exportCertPem();
Exports the digital certificate to an unencrypted PEM formatted string. Returns a null on failure
const char * exportCertXml();
To be documented soon...
const char * 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
const char * getPrivateKeyPem();
Exports the certificate's private key to a PEM string (if the private key is available). Returns a null on failure
const char * issuerC();
The certificate issuer's country. Returns a null on failure
const char * issuerCN();
The certificate issuer's common name. Returns a null on failure
const char * issuerDN();
The issuer's full distinguished name. Returns a null on failure
const char * issuerE();
The certificate issuer's email address. Returns a null on failure
const char * issuerL();
The certificate issuer's locality, which could be a city, count, township, or other geographic region. Returns a null on failure
const char * issuerO();
The certificate issuer's organization, which is typically the company name. Returns a null on failure
const char * issuerOU();
The certificate issuer's organizational unit, which is the unit within the organization. Returns a null on failure
const char * issuerS();
The certificate issuer's state or province. Returns a null on failure
const char * keyContainerName();
(Relevant only when running on a Microsoft Windows operating system.) 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. Returns a null on failure
const char * lastErrorHtml();
Error information in HTML format for the last method called.The "const char *" returned by this method will be overwritten or become invalid when other methods returning "const char *" are called. The calling application should copy the returned string to a safe place immediately. Returns a null on failure
const char * lastErrorText();
Error information in plain-text format for the last method called.The "const char *" returned by this method will be overwritten or become invalid when other methods returning "const char *" are called. The calling application should copy the returned string to a safe place immediately. Returns a null on failure
const char * lastErrorXml();
Error information in XML format for the last method called.The "const char *" returned by this method will be overwritten or become invalid when other methods returning "const char *" are called. The calling application should copy the returned string to a safe place immediately. Returns a null on failure
const char * ocspUrl();
To be documented soon...
const char * rfc822Name();
The RFC-822 name of the certificate. (Also known as the Subject Alternative Name.) Returns a null on failure
const char * serialNumber();
The certificate's serial number as a hexidecimal string. Returns a null on failure
const char * sha1Thumbprint();
Hexidecimal string of the SHA-1 thumbprint for the certificate. Returns a null on failure
const char * subjectC();
The certificate subject's country. Returns a null on failure
const char * subjectCN();
The certificate subject's common name. Returns a null on failure
const char * subjectDN();
The certificate subject's full distinguished name. Returns a null on failure
const char * subjectE();
The certificate subject's email address. Returns a null on failure
const char * subjectL();
The certificate subject's locality, which could be a city, count, township, or other geographic region. Returns a null on failure
const char * subjectO();
The certificate subject's organization, which is typically the company name. Returns a null on failure
const char * subjectOU();
The certificate subject's organizational unit, which is the unit within the organization. Returns a null on failure
const char * subjectS();
The certificate subject's state or province. Returns a null on failure
const char * version();
The version of this component, such as "1.0" Returns a null on failure
|