Sample code for 30+ languages & platforms
Unicode C

RSA Import Private Key

See more RSA Examples

Shows how to select/import a private key for RSA signing or decryption.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkPrivateKeyW.h>
#include <C_CkRsaW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkPrivateKeyW privKey;
    const wchar_t *password;
    HCkRsaW rsa;

    success = FALSE;

    privKey = CkPrivateKeyW_Create();
    password = L"secret";
    //  In all Chilkat methods expecting a path, you pass either absolute or relative paths.
    success = CkPrivateKeyW_LoadAnyFormatFile(privKey,L"rsaKeys/myTestRsaPrivate.pem",password);
    if (success == FALSE) {
        wprintf(L"%s\n",CkPrivateKeyW_lastErrorText(privKey));
        CkPrivateKeyW_Dispose(privKey);
        return;
    }

    rsa = CkRsaW_Create();

    //  Tell the RSA object to use the private key (i.e. import the private key)
    CkRsaW_UsePrivateKey(rsa,privKey);


    CkPrivateKeyW_Dispose(privKey);
    CkRsaW_Dispose(rsa);

    }