PrivateKey Unicode C Reference Documentation

PrivateKey

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

Create/Dispose

HCkPrivateKeyW CkPrivateKeyW_Create(void);

Creates an instance of the HCkPrivateKeyW 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 CkPrivateKeyW_Dispose(HCkPrivateKeyW handle);

Objects created by calling CkPrivateKeyW_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkPrivateKeyW_Dispose.

Properties

int CkPrivateKeyW_getBitLength(HCkPrivateKeyW cHandle);

Introduced in version 9.5.0.49

The bit length (strength) of the private key.

void CkPrivateKeyW_getDebugLogFilePath(HCkPrivateKeyW cHandle, HCkString retval);

void CkPrivateKeyW_putDebugLogFilePath(HCkPrivateKeyW cHandle, const wchar_t *newVal);

const wchar_t *CkPrivateKeyW_debugLogFilePath(HCkPrivateKeyW cHandle);

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

void CkPrivateKeyW_getKeyType(HCkPrivateKeyW cHandle, HCkString retval);

const wchar_t *CkPrivateKeyW_keyType(HCkPrivateKeyW cHandle);

Introduced in version 9.5.0.52

The type of private key. Can be "empty", "rsa", "dsa", or "ecc".

void CkPrivateKeyW_getLastErrorHtml(HCkPrivateKeyW cHandle, HCkString retval);

const wchar_t *CkPrivateKeyW_lastErrorHtml(HCkPrivateKeyW cHandle);

Provides information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

void CkPrivateKeyW_getLastErrorText(HCkPrivateKeyW cHandle, HCkString retval);

const wchar_t *CkPrivateKeyW_lastErrorText(HCkPrivateKeyW cHandle);

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

Concept of LastErrorText

LastErrorText Standard Information

void CkPrivateKeyW_getLastErrorXml(HCkPrivateKeyW cHandle, HCkString retval);

const wchar_t *CkPrivateKeyW_lastErrorXml(HCkPrivateKeyW cHandle);

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

BOOL CkPrivateKeyW_getLastMethodSuccess(HCkPrivateKeyW cHandle);

void CkPrivateKeyW_putLastMethodSuccess(HCkPrivateKeyW cHandle, BOOL newVal);

Introduced in version 9.5.0.52

Indicate whether the last method call succeeded or failed. A value of TRUE indicates success, a value of FALSE indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = TRUE and failure = FALSE.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to TRUE. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

void CkPrivateKeyW_getPkcs8EncryptAlg(HCkPrivateKeyW cHandle, HCkString retval);

void CkPrivateKeyW_putPkcs8EncryptAlg(HCkPrivateKeyW cHandle, const wchar_t *newVal);

const wchar_t *CkPrivateKeyW_pkcs8EncryptAlg(HCkPrivateKeyW cHandle);

Introduced in version 9.5.0.49

The encryption algorithm to be used when exporting the key to encrypted PKCS8. The default value is "3des". Possible choices also include "aes128", "aes192", and "aes256". All of the encryption algorithm choices use CBC mode.

BOOL CkPrivateKeyW_getVerboseLogging(HCkPrivateKeyW cHandle);

void CkPrivateKeyW_putVerboseLogging(HCkPrivateKeyW cHandle, BOOL newVal);

If set to TRUE, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is FALSE. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

void CkPrivateKeyW_getVersion(HCkPrivateKeyW cHandle, HCkString retval);

const wchar_t *CkPrivateKeyW_version(HCkPrivateKeyW cHandle);

Version of the component/library, such as "9.5.0.63"

Methods

BOOL CkPrivateKeyW_GetJwk(HCkPrivateKeyW cHandle, const wchar_t *outStr);

const wchar_t *CkPrivateKeyW_getJwk(HCkPrivateKeyW cHandle);

Introduced in version 9.5.0.66

Gets the private key in JWK (JSON Web Key) format.

RSA keys have this JWK format:

         {"kty":"RSA",
          "n":"0vx7agoebGcQ ... JzKnqDKgw",
          "e":"AQAB",
          "d":"X4cTteJY_gn4F ... 4jfcKoAC8Q",
          "p":"83i-7IvMGXoMX ... vn7O0nVbfs",
          "q":"3dfOR9cuYq-0S ... 4vIcb6yelxk",
          "dp":"G4sPXkc6Ya9 ... 8YeiKkTiBj0",
          "dq":"s9lAH9fggBso ... w494Q_cgk",
          "qi":"GyM_p6JrXySi ... zTKhAVRU"}

ECC keys have this JWK format.

         {"kty":"EC",
          "crv":"P-256",
          "x":"MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4",
          "y":"4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM",
          "d":"870MB6gfuTJ4HtUnUvYMyJpr5eUZNP4Bk43bVdj3eAE"}

Returns TRUE for success, FALSE for failure.

Get RSA Private Key in JWK Format (JSON Web Key)

Get ECC Private Key in JWK Format (JSON Web Key)

BOOL CkPrivateKeyW_GetJwkThumbprint(HCkPrivateKeyW cHandle, const wchar_t *hashAlg, const wchar_t *outStr);

const wchar_t *CkPrivateKeyW_getJwkThumbprint(HCkPrivateKeyW cHandle, const wchar_t *hashAlg);

Introduced in version 9.5.0.66

Returns the JWK thumbprint for the private key. This is the thumbprint of the JSON Web Key (JWK) as per RFC 7638.

Returns TRUE for success, FALSE for failure.

Compute JWK Thumbprint for RSA and EC Private Keys

BOOL CkPrivateKeyW_GetPkcs1(HCkPrivateKeyW cHandle, const unsigned char * outBytes);

Introduced in version 9.5.0.58

Gets the private key in unencrypted binary DER format, preferring PKCS1 if possible.

RSA keys are returned in PKCS1 ASN.1 DER format:

RSAPrivateKey ::= SEQUENCE {
    version           Version,
    modulus           INTEGER,  -- n
    publicExponent    INTEGER,  -- e
    privateExponent   INTEGER,  -- d
    prime1            INTEGER,  -- p
    prime2            INTEGER,  -- q
    exponent1         INTEGER,  -- d mod (p-1)
    exponent2         INTEGER,  -- d mod (q-1)
    coefficient       INTEGER,  -- (inverse of q) mod p
    otherPrimeInfos   OtherPrimeInfos OPTIONAL
}

DSA keys are returned in this ASN.1 DER format:

SEQUENCE(6 elem)
    INTEGER 0
    INTEGER(2048 bit) (p) 
    INTEGER(160 bit) (q) 
    INTEGER(2044 bit) (g) 
    INTEGER(2040 bit) (y - public key) 
    INTEGER(156 bit) (x - private key) 

ECC keys are returned in this ASN.1 DER format:

(from RFC 5915)
ECPrivateKey ::= SEQUENCE {
    version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
    privateKey     OCTET STRING,
    parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
    publicKey  [1] BIT STRING OPTIONAL (This is the ANSI X9.63 public key format.)

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_GetPkcs1ENC(HCkPrivateKeyW cHandle, const wchar_t *encoding, const wchar_t *outStr);

const wchar_t *CkPrivateKeyW_getPkcs1ENC(HCkPrivateKeyW cHandle, const wchar_t *encoding);

Introduced in version 9.5.0.52

Gets the private key in unencrypted binary DER format, preferring PKCS1 if possible, and returns in an encoded string, as specified by the encoding argument.

RSA keys are returned in PKCS1 ASN.1 DER format:

RSAPrivateKey ::= SEQUENCE {
    version           Version,
    modulus           INTEGER,  -- n
    publicExponent    INTEGER,  -- e
    privateExponent   INTEGER,  -- d
    prime1            INTEGER,  -- p
    prime2            INTEGER,  -- q
    exponent1         INTEGER,  -- d mod (p-1)
    exponent2         INTEGER,  -- d mod (q-1)
    coefficient       INTEGER,  -- (inverse of q) mod p
    otherPrimeInfos   OtherPrimeInfos OPTIONAL
}

DSA keys are returned in this ASN.1 DER format:

SEQUENCE(6 elem)
    INTEGER 0
    INTEGER(2048 bit) (p) 
    INTEGER(160 bit) (q) 
    INTEGER(2044 bit) (g) 
    INTEGER(2040 bit) (y - public key) 
    INTEGER(156 bit) (x - private key) 

ECC keys are returned in this ASN.1 DER format:

(from RFC 5915)
ECPrivateKey ::= SEQUENCE {
    version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
    privateKey     OCTET STRING,
    parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
    publicKey  [1] BIT STRING OPTIONAL (This is the ANSI X9.63 public key format.)

Returns TRUE for success, FALSE for failure.

Supported Binary Encodings

BOOL CkPrivateKeyW_GetPkcs1Pem(HCkPrivateKeyW cHandle, const wchar_t *outStr);

const wchar_t *CkPrivateKeyW_getPkcs1Pem(HCkPrivateKeyW cHandle);

Introduced in version 9.5.0.58

Gets the private key in non-encrypted PEM format, preferring PKCS1 over PKCS8 if possible for the key type.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_GetPkcs8(HCkPrivateKeyW cHandle, const unsigned char * outData);

Gets the private key in unencrypted PKCS8 format.

RSA keys are returned in PKCS8 ASN.1 DER format:

SEQUENCE                  // PrivateKeyInfo
+- INTEGER                // Version - 0 (v1998)
+- SEQUENCE               // AlgorithmIdentifier
   +- OID                 // 1.2.840.113549.1.1.1
   +- NULL                // Optional Parameters
+- OCTETSTRING            // PrivateKey
   +- SEQUENCE            // RSAPrivateKey
      +- INTEGER(0)       // Version - v1998(0)
      +- INTEGER(N)       // N
      +- INTEGER(E)       // E
      +- INTEGER(D)       // D
      +- INTEGER(P)       // P
      +- INTEGER(Q)       // Q
      +- INTEGER(DP)      // d mod p-1
      +- INTEGER(DQ)      // d mod q-1
      +- INTEGER(Inv Q)   // INV(q) mod p

DSA keys are returned in this ASN.1 DER format:

SEQUENCE                 // PrivateKeyInfo
+- INTEGER                 // Version
+- SEQUENCE              // AlgorithmIdentifier
    +- OID                       // 1.2.840.10040.4.1
    +- SEQUENCE           // DSS-Params (Optional Parameters)
	+- INTEGER(P)      // P
	+- INTEGER(Q)      // Q
	+- INTEGER(G)      // G
    +- OCTETSTRING             // PrivateKey
	+- INTEGER(X)      // DSAPrivateKey X

ECC keys are returned in this ASN.1 DER format:

(from RFC 5915)
ECPrivateKey ::= SEQUENCE {
    version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
    privateKey     OCTET STRING,
    parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
    publicKey  [1] BIT STRING OPTIONAL (This is the ANSI X9.63 public key format.)

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_GetPkcs8ENC(HCkPrivateKeyW cHandle, const wchar_t *encoding, const wchar_t *outStr);

const wchar_t *CkPrivateKeyW_getPkcs8ENC(HCkPrivateKeyW cHandle, const wchar_t *encoding);

Introduced in version 9.5.0.52

Gets the private key in unencrypted PKCS8 format and returned in an encoded string, as specified by the encoding argument.

Returns TRUE for success, FALSE for failure.

Supported Binary Encodings

Generate RSA Key and return Base64 PKCS8 Private Key

BOOL CkPrivateKeyW_GetPkcs8Encrypted(HCkPrivateKeyW cHandle, const wchar_t *password, const unsigned char * outBytes);

Writes the private key to password-protected PKCS8 format. The Pkcs8EncryptAlg property controls the encryption algorithm used to encrypt.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_GetPkcs8EncryptedENC(HCkPrivateKeyW cHandle, const wchar_t *encoding, const wchar_t *password, const wchar_t *outStr);

const wchar_t *CkPrivateKeyW_getPkcs8EncryptedENC(HCkPrivateKeyW cHandle, const wchar_t *encoding, const wchar_t *password);

Introduced in version 9.5.0.52

Writes the private key to password-protected PKCS8 format and returns as an encoded string as specified by the encoding argument. The Pkcs8EncryptAlg property controls the encryption algorithm used to encrypt.

Returns TRUE for success, FALSE for failure.

Supported Binary Encodings

BOOL CkPrivateKeyW_GetPkcs8EncryptedPem(HCkPrivateKeyW cHandle, const wchar_t *password, const wchar_t *outStr);

const wchar_t *CkPrivateKeyW_getPkcs8EncryptedPem(HCkPrivateKeyW cHandle, const wchar_t *password);

Writes the private key to password-protected PKCS8 PEM format. The Pkcs8EncryptAlg property controls the encryption algorithm used to encrypt.

Returns TRUE for success, FALSE for failure.

Generate RSA Key and Export to Encrypted PEM

BOOL CkPrivateKeyW_GetPkcs8Pem(HCkPrivateKeyW cHandle, const wchar_t *outStr);

const wchar_t *CkPrivateKeyW_getPkcs8Pem(HCkPrivateKeyW cHandle);

Gets the private key in PKCS8 PEM format.

Returns TRUE for success, FALSE for failure.

HCkPublicKeyW CkPrivateKeyW_GetPublicKey(HCkPrivateKeyW cHandle);

Introduced in version 9.5.0.52

Returns the public key portion of the private key as a public key object.

Returns NULL on failure

Convert RSA Private Key to Public Key

Get ECC Public Key from ECC Private Key

BOOL CkPrivateKeyW_GetRsaDer(HCkPrivateKeyW cHandle, const unsigned char * outData);

This method is deprecated. It will be removed in a future version.

Gets the private key in PKCS1 DER format. This method is deprecated and is replaced by the GetPkcs1Der method (given that this object may contain a non-RSA key).

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_GetRsaPem(HCkPrivateKeyW cHandle, const wchar_t *outStr);

const wchar_t *CkPrivateKeyW_getRsaPem(HCkPrivateKeyW cHandle);

This method is deprecated. It will be removed in a future version.

Gets the private key in PKCS1 PEM format. This method is deprecated and is replaced by the GetPkcs1Pem and GetPkcs8Pem methods (given that this object may contain a non-RSA key).

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_GetXml(HCkPrivateKeyW cHandle, const wchar_t *outStr);

const wchar_t *CkPrivateKeyW_getXml(HCkPrivateKeyW cHandle);

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

RSA keys have this XML format:

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

DSA keys have this XML format:

<DSAKeyValue>
	<P>...</P>
	<Q>...</Q>
	<G>...</G>
	<Y>...</Y>
	<X>...</X>
</DSAKeyValue>

ECC keys have this XML format. The CURVE_NAME could be one of secp256r1, secp384r1, secp521r1, secp256k1 (or others as new curves are supported.)

<ECCKeyValue curve="CURVE_NAME">...</ECCKeyValue>

Returns TRUE for success, FALSE for failure.

Get RSA Key Modulus from .cer or .key

BOOL CkPrivateKeyW_LoadEncryptedPem(HCkPrivateKeyW cHandle, const wchar_t *pemStr, const wchar_t *password);

Loads the private key from an in-memory encrypted PEM string. An encrypted PEM contains the private key in encrypted PKCS#8 format, where the data begins and ends with the following tags:

-----BEGIN ENCRYPTED PRIVATE KEY-----
BASE64 ENCODED DATA
-----END ENCRYPTED PRIVATE KEY-----

For those requiring a deeper understanding: The base64 data contains ASN.1 DER with the following structure:

EncryptedPrivateKeyInfo ::= SEQUENCE {
  encryptionAlgorithm  EncryptionAlgorithmIdentifier,
  encryptedData        EncryptedData
}

EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier

EncryptedData ::= OCTET STRING

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

Compute JWK Thumbprint for RSA and EC Private Keys

BOOL CkPrivateKeyW_LoadEncryptedPemFile(HCkPrivateKeyW cHandle, const wchar_t *path, const wchar_t *password);

Loads a private key from an encrypted PEM file.

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_LoadJwk(HCkPrivateKeyW cHandle, const wchar_t *jsonStr);

Introduced in version 9.5.0.66

Loads a private key from an JWK (JSON Web Key) string.

RSA keys have this JWK format:

         {"kty":"RSA",
          "n":"0vx7agoebGcQ ... JzKnqDKgw",
          "e":"AQAB",
          "d":"X4cTteJY_gn4F ... 4jfcKoAC8Q",
          "p":"83i-7IvMGXoMX ... vn7O0nVbfs",
          "q":"3dfOR9cuYq-0S ... 4vIcb6yelxk",
          "dp":"G4sPXkc6Ya9 ... 8YeiKkTiBj0",
          "dq":"s9lAH9fggBso ... w494Q_cgk",
          "qi":"GyM_p6JrXySi ... zTKhAVRU"}

ECC keys have this JWK format.

         {"kty":"EC",
          "crv":"P-256",
          "x":"MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4",
          "y":"4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM",
          "d":"870MB6gfuTJ4HtUnUvYMyJpr5eUZNP4Bk43bVdj3eAE"}

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

Load RSA Private Key from JWK Format (JSON Web Key)

Load ECC Private Key from JWK Format (JSON Web Key)

JWE using RSAES-OAEP and AES GCM

BOOL CkPrivateKeyW_LoadPem(HCkPrivateKeyW cHandle, const wchar_t *str);

Loads the private key from an in-memory PEM string. If the PEM contains an encrypted private key, then the LoadEncryptedPem method should instead be called. This method is for loading an unencrypted private key stored in PEM using PKCS#1 or PKCS#8.

A private key stored in PKCS#1 format begins and ends with the tags:

-----BEGIN RSA PRIVATE KEY-----
BASE64 ENCODED DATA
-----END RSA PRIVATE KEY-----

For those requiring a deeper understanding, the PKCS1 base64 contains ASN.1 in DER encoding with the following structure:

RSAPrivateKey ::= SEQUENCE {
  version           Version,
  modulus           INTEGER,  -- n
  publicExponent    INTEGER,  -- e
  privateExponent   INTEGER,  -- d
  prime1            INTEGER,  -- p
  prime2            INTEGER,  -- q
  exponent1         INTEGER,  -- d mod (p-1)
  exponent2         INTEGER,  -- d mod (q-1)
  coefficient       INTEGER,  -- (inverse of q) mod p
  otherPrimeInfos   OtherPrimeInfos OPTIONAL
}

A private key stored in PKCS#8 format begins and ends with the tags:

-----BEGIN PRIVATE KEY-----
BASE64 ENCODED DATA
-----END PRIVATE KEY-----

For those requiring a deeper understanding, the PKCS8 base64 contains ASN.1 in DER encoding with the following structure:

PrivateKeyInfo ::= SEQUENCE {
  version         Version,
  algorithm       AlgorithmIdentifier,
  PrivateKey      BIT STRING
}

AlgorithmIdentifier ::= SEQUENCE {
  algorithm       OBJECT IDENTIFIER,
  parameters      ANY DEFINED BY algorithm OPTIONAL
}

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

Compute JWK Thumbprint for RSA and EC Private Keys

BOOL CkPrivateKeyW_LoadPemFile(HCkPrivateKeyW cHandle, const wchar_t *path);

Loads a private key from a PEM file.

Returns TRUE for success, FALSE for failure.

Create PKCS1 RSA Signature with PEM Private Key

BOOL CkPrivateKeyW_LoadPkcs1(HCkPrivateKeyW cHandle, const unsigned char * data);

Introduced in version 9.5.0.58

Loads an RSA, ECC, or DSA private key from binary DER.

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_LoadPkcs1File(HCkPrivateKeyW cHandle, const wchar_t *path);

Introduced in version 9.5.0.58

Loads a private key from a PKCS1 file.

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_LoadPkcs8(HCkPrivateKeyW cHandle, const unsigned char * data);

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

For those requiring a deeper understanding, the PKCS8 contains ASN.1 in DER encoding with the following structure:

PrivateKeyInfo ::= SEQUENCE {
  version         Version,
  algorithm       AlgorithmIdentifier,
  PrivateKey      BIT STRING
}

AlgorithmIdentifier ::= SEQUENCE {
  algorithm       OBJECT IDENTIFIER,
  parameters      ANY DEFINED BY algorithm OPTIONAL
}

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_LoadPkcs8Encrypted(HCkPrivateKeyW cHandle, const unsigned char * data, const wchar_t *password);

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

For those requiring a deeper understanding, the encrypted PKCS8 contains ASN.1 in DER encoding with the following structure:

EncryptedPrivateKeyInfo ::= SEQUENCE {
  encryptionAlgorithm  EncryptionAlgorithmIdentifier,
  encryptedData        EncryptedData
}

EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier

EncryptedData ::= OCTET STRING

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_LoadPkcs8EncryptedFile(HCkPrivateKeyW cHandle, const wchar_t *path, const wchar_t *password);

Loads a private key from an encrypted PKCS8 file.

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

RSA Sign with PKCS8 Encrypted Key

BOOL CkPrivateKeyW_LoadPkcs8File(HCkPrivateKeyW cHandle, const wchar_t *path);

Loads a private key from a PKCS8 file.

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_LoadPvk(HCkPrivateKeyW cHandle, const unsigned char * data, const wchar_t *password);

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

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_LoadPvkFile(HCkPrivateKeyW cHandle, const wchar_t *path, const wchar_t *password);

Loads a private key from a PVK format file.

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_LoadRsaDer(HCkPrivateKeyW cHandle, const unsigned char * data);

This method is deprecated. It will be removed in a future version.

This method is deprecated. Deprecated methods will be removed at some point in the future. Applications should instead call LoadPkcs1.

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

For those requiring a deeper understanding, the PKCS1 contains ASN.1 in DER encoding with the following structure:

RSAPrivateKey ::= SEQUENCE {
  version           Version,
  modulus           INTEGER,  -- n
  publicExponent    INTEGER,  -- e
  privateExponent   INTEGER,  -- d
  prime1            INTEGER,  -- p
  prime2            INTEGER,  -- q
  exponent1         INTEGER,  -- d mod (p-1)
  exponent2         INTEGER,  -- d mod (q-1)
  coefficient       INTEGER,  -- (inverse of q) mod p
  otherPrimeInfos   OtherPrimeInfos OPTIONAL
}

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_LoadRsaDerFile(HCkPrivateKeyW cHandle, const wchar_t *path);

This method is deprecated. It will be removed in a future version.

This method is deprecated. Deprecated methods will be removed at some point in the future. Applications should instead call LoadPkcs1File.

Loads a private key from an RSA DER format file.

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

About RSA Public/Private Keys

BOOL CkPrivateKeyW_LoadXml(HCkPrivateKeyW cHandle, const wchar_t *xml);

Loads a private key from an XML string.

RSA keys have this XML format:

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

DSA keys have this XML format:

<DSAKeyValue>
	<P>...</P>
	<Q>...</Q>
	<G>...</G>
	<Y>...</Y>
	<X>...</X>
</DSAKeyValue>

ECC keys have this XML format. The CURVE_NAME could be one of secp256r1, secp384r1, secp521r1, secp256k1 (or others as new curves are supported.)

<ECCKeyValue curve="CURVE_NAME">...</ECCKeyValue>

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_LoadXmlFile(HCkPrivateKeyW cHandle, const wchar_t *path);

Loads a private key from an XML file.

Note: Each of the private key Load* methods willl auto-recognize the content and will parse appropriately. The private key should be successfully loaded even when the wrong format data is passed to the wrong method.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_SaveLastError(HCkPrivateKeyW cHandle, const wchar_t *path);

Saves the last-error information (the contents of LastErrorXml) to an XML formatted file.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_SavePemFile(HCkPrivateKeyW cHandle, const wchar_t *path);

Introduced in version 9.5.0.58

Saves the private key to an unencrypted PKCS1 PEM format file.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_SavePkcs1File(HCkPrivateKeyW cHandle, const wchar_t *path);

Introduced in version 9.5.0.58

Saves the private key to an unencrypted binary PKCS1 format file.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_SavePkcs8EncryptedFile(HCkPrivateKeyW cHandle, const wchar_t *password, const wchar_t *path);

Saves the private key to a password-protected PKCS8 format file. The Pkcs8EncryptAlg property controls the encryption algorithm used to encrypt.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_SavePkcs8EncryptedPemFile(HCkPrivateKeyW cHandle, const wchar_t *password, const wchar_t *path);

Saves the private key to a password-protected PKCS8 PEM format file. The Pkcs8EncryptAlg property controls the encryption algorithm used to encrypt.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_SavePkcs8File(HCkPrivateKeyW cHandle, const wchar_t *path);

Saves the private key to an unencrypted binary PKCS8 format file.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_SavePkcs8PemFile(HCkPrivateKeyW cHandle, const wchar_t *path);

Saves the private key to a PKCS8 PEM format file.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_SaveRsaDerFile(HCkPrivateKeyW cHandle, const wchar_t *path);

This method is deprecated. It will be removed in a future version.

This method is deprecated and applications should instead call SavePkcs1File.

Saves the private key to a binary PKCS1 DER format file.

Returns TRUE for success, FALSE for failure.

BOOL CkPrivateKeyW_SaveRsaPemFile(HCkPrivateKeyW cHandle, const wchar_t *path);

This method is deprecated. It will be removed in a future version.

This method is deprecated. Applications should instead call SavePemFile.

Saves the private key to a PKCS1 PEM format file.

Returns TRUE for success, FALSE for failure.

Generate RSA Public/Private Key Pair and Export to PEM

BOOL CkPrivateKeyW_SaveXmlFile(HCkPrivateKeyW cHandle, const wchar_t *path);

Saves the private key to an XML file.

Returns TRUE for success, FALSE for failure.