PublicKey C Library Reference

PublicKey

* This is a freeware class/C library/library.

Represents an RSA public key. Provides methods for importing and exporting to/from OpenSSL DER and PEM formats, RSA DER format, and XML format. Public keys can be imported/exported to both memory and files.

Create/Dispose

HCkPublicKey CkPublicKey_Create(void);

Creates an instance of the CkPublicKey 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 CkPublicKey_Dispose(HCkPublicKey handle);

Objects created by calling CkPublicKey_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 CkPublicKey_getLastErrorHtml(HCkPublicKey cHandle, HCkString retval);

Error information in HTML format for the last method called.

void CkPublicKey_getLastErrorText(HCkPublicKey cHandle, HCkString retval);

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

void CkPublicKey_getLastErrorXml(HCkPublicKey cHandle, HCkString retval);

Error information in XML format for the last method called.

BOOL CkPublicKey_getUtf8(HCkPublicKey cHandle);
void CkPublicKey_putUtf8(HCkPublicKey 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.

C "Methods"

BOOL CkPublicKey_GetOpenSslDer(HCkPublicKey cHandle, HCkByteData outData);

Gets the public key in OpenSSL DER format.

BOOL CkPublicKey_GetOpenSslPem(HCkPublicKey cHandle, HCkString outStr);

Gets the public key in OpenSSL PEM format.

BOOL CkPublicKey_GetRsaDer(HCkPublicKey cHandle, HCkByteData outData);

Gets the public key in RSA DER format.

BOOL CkPublicKey_GetXml(HCkPublicKey cHandle, HCkString outStr);

Gets the public key in XML format. The XML has this format where the key parts are base64 encoded:

<RSAKeyValue>
  <Modulus>...</Modulus>
  <Exponent>...</Exponent>
</RSAKeyValue>

BOOL CkPublicKey_LoadOpenSslDer(HCkPublicKey cHandle, HCkByteData data);

Loads a public key from in-memory OpenSSL DER formatted byte data.

Returns TRUE for success, FALSE for failure.

BOOL CkPublicKey_LoadOpenSslDerFile(HCkPublicKey cHandle, const char *filename);

Loads a public key from an OpenSSL DER format file.

Returns TRUE for success, FALSE for failure.

BOOL CkPublicKey_LoadOpenSslPem(HCkPublicKey cHandle, const char *str);

Loads a public key from an OpenSSL PEM string.

Returns TRUE for success, FALSE for failure.

BOOL CkPublicKey_LoadOpenSslPemFile(HCkPublicKey cHandle, const char *filename);

Loads a public key from an OpenSSL PEM file.

Returns TRUE for success, FALSE for failure.

BOOL CkPublicKey_LoadPkcs1Pem(HCkPublicKey cHandle, const char *str);

To be documented soon...

BOOL CkPublicKey_LoadRsaDer(HCkPublicKey cHandle, HCkByteData data);

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

Returns TRUE for success, FALSE for failure.

BOOL CkPublicKey_LoadRsaDerFile(HCkPublicKey cHandle, const char *filename);

Loads a public key from an RSA DER formatted file.

Returns TRUE for success, FALSE for failure.

BOOL CkPublicKey_LoadXml(HCkPublicKey cHandle, const char *xml);

Loads a public key from an XML string.

Returns TRUE for success, FALSE for failure.

BOOL CkPublicKey_LoadXmlFile(HCkPublicKey cHandle, const char *filename);

Loads a public key from an XML file.

Returns TRUE for success, FALSE for failure.

BOOL CkPublicKey_SaveLastError(HCkPublicKey cHandle, const char *filename);

Saves the last error information to an XML formatted file.

BOOL CkPublicKey_SaveOpenSslDerFile(HCkPublicKey cHandle, const char *filename);

Saves the public key to an OpenSSL DER format file.

Returns TRUE for success, FALSE for failure.

BOOL CkPublicKey_SaveOpenSslPemFile(HCkPublicKey cHandle, const char *filename);

Saves the public key to an OpenSSL PEM format file.

Returns TRUE for success, FALSE for failure.

BOOL CkPublicKey_SaveRsaDerFile(HCkPublicKey cHandle, const char *filename);

Saves the public key to an RSA DER format file.

Returns TRUE for success, FALSE for failure.

BOOL CkPublicKey_SaveXmlFile(HCkPublicKey cHandle, const char *filename);

Saves the public key to an XML file.

Returns TRUE for success, FALSE for failure.

const char *CkPublicKey_getOpenSslPem(HCkPublicKey cHandle);

Gets the public key in OpenSSL PEM format.

Returns a null on failure

const char *CkPublicKey_getXml(HCkPublicKey cHandle);

Gets the public key in XML format. The XML has this format where the key parts are base64 encoded:

<RSAKeyValue>
  <Modulus>...</Modulus>
  <Exponent>...</Exponent>
</RSAKeyValue>

Returns a null on failure

const char *CkPublicKey_lastErrorHtml(HCkPublicKey cHandle);

Error information in HTML format for the last method called.

Returns a null on failure

const char *CkPublicKey_lastErrorText(HCkPublicKey cHandle);

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

Returns a null on failure

const char *CkPublicKey_lastErrorXml(HCkPublicKey cHandle);

Error information in XML format for the last method called.

Returns a null on failure