CkPrivateKey C++ Class Reference (Visual C++)

CkPrivateKey

* This is a freeware class/component/library.

Represents an RSA private key. Provides methods for importing and exporting to/from PEM, DER, PKCS8, PVK, and XML formats. Private keys can be imported/exported to both memory and files.

Properties

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

Methods

bool GetPkcs8(CkByteData & data);

Gets the private key in PKCS8 format.

The PKCS8 bytes are written to the CkByteData output-only argument.

bool GetPkcs8Encrypted(const char * password, CkByteData & outBytes);

Writes the private key to password-protected PKCS8 format.

bool GetPkcs8EncryptedPem(const char * password, CkString & outStr);

Writes the private key to password-protected PKCS8 PEM format.

Returns true for success, false for failure.

bool GetPkcs8Pem(CkString & str);

Gets the private key in PKCS8 PEM format.

Returns true for success, false for failure.

bool GetRsaDer(CkByteData & data);

Gets the private key in RSA DER format.

The DER bytes are written to the CkByteData output-only argument.

bool GetRsaPem(CkString & str);

Gets the private key in RSA PEM format.

Returns true for success, false for failure.

bool GetXml(CkString & str);

Returns the private key in XML format. The private key is returned unencrypted and the parts are base64 encoded. The XML has this structure:

<RSAKeyValue>
  <Modulus>...</Modulus>
  <Exponent>...</Exponent>
  <P>...</P>
  <Q>...</Q>
  <DP>...</DP>
  <DQ>...</DQ>
  <InverseQ>...</InverseQ>
  <D>...</D>
</RSAKeyValue>

Returns true for success, false for failure.

bool LoadEncryptedPem(const char * pemStr, const char * password);

Loads the private key from an in-memory encrypted PEM string.

Returns true for success, false for failure.

bool LoadEncryptedPemFile(const char * filename, const char * password);

Loads a private key from an encrypted PEM file.

Returns true for success, false for failure.

bool LoadPem(const char * str);

Loads the private key from an in-memory PEM string.

Returns true for success, false for failure.

bool LoadPemFile(const char * filename);

Loads a private key from a PEM file.

Returns true for success, false for failure.

bool LoadPkcs8(CkByteData & data);

Loads a private key from in-memory PKCS8 byte data.

Returns true for success, false for failure.

bool LoadPkcs8Encrypted(CkByteData & data, const char * password);

Loads a private key from in-memory password-protected PKCS8 byte data.

Returns true for success, false for failure.

bool LoadPkcs8EncryptedFile(const char * filename, const char * password);

Loads a private key from a password-protected PKCS8 file.

Returns true for success, false for failure.

bool LoadPkcs8File(const char * filename);

Loads a private key from a PKCS8 file.

Returns true for success, false for failure.

bool LoadPvk(CkByteData & data, const char * password);

Loads a private key from in-memory PVK byte data.

Returns true for success, false for failure.

bool LoadPvkFile(const char * filename, const char * password);

Loads a private key from a PVK format file.

Returns true for success, false for failure.

bool LoadRsaDer(CkByteData & data);

Loads a private key from in-memory RSA DER byte data.

Returns true for success, false for failure.

bool LoadRsaDerFile(const char * filename);

Loads a private key from an RSA DER format file.

Returns true for success, false for failure.

bool LoadXml(const char * xml);

Loads a private key from an in-memory XML string.

Returns true for success, false for failure.

bool LoadXmlFile(const char * filename);

Loads a private key from an XML file.

Returns true for success, false for failure.

bool SaveLastError(const char * filename);

Saves the last error information to an XML formatted file.

bool SavePkcs8EncryptedFile(const char * password, const char * filename);

Saves the private key to a password-protected PKCS8 format file.

Returns true for success, false for failure.

bool SavePkcs8EncryptedPemFile(const char * password, const char * filename);

Saves the private key to a password-protected PKCS8 PEM format file.

Returns true for success, false for failure.

bool SavePkcs8File(const char * filename);

Saves the private key to a PKCS8 format file.

Returns true for success, false for failure.

bool SavePkcs8PemFile(const char * filename);

Saves the private key to a PKCS8 PEM format file.

Returns true for success, false for failure.

bool SaveRsaDerFile(const char * filename);

Saves the private key to a RSA DER format file.

Returns true for success, false for failure.

bool SaveRsaPemFile(const char * filename);

Saves the private key to a RSA PEM format file.

Returns true for success, false for failure.

bool SaveXmlFile(const char * filename);

Saves the private key to an XML file.

Returns true for success, false for failure.

const char * getPkcs8EncryptedPem(const char * password);

Writes the private key to password-protected PKCS8 PEM format.

const char * getPkcs8Pem();

Gets the private key in PKCS8 PEM format.

const char * getRsaPem();

Gets the private key in RSA PEM format.

const char * getXml();

Returns the private key in XML format. The private key is returned unencrypted and the parts are base64 encoded. The XML has this structure:

<RSAKeyValue>
  <Modulus>...</Modulus>
  <Exponent>...</Exponent>
  <P>...</P>
  <Q>...</Q>
  <DP>...</DP>
  <DQ>...</DQ>
  <InverseQ>...</InverseQ>
  <D>...</D>
</RSAKeyValue>

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.

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.

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.