Sample code for 30+ languages & platforms
C

RSA Import Private Key

See more RSA Examples

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

Chilkat C Downloads

C
#include <C_CkPrivateKey.h>
#include <C_CkRsa.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkPrivateKey privKey;
    const char *password;
    HCkRsa rsa;

    success = FALSE;

    privKey = CkPrivateKey_Create();
    password = "secret";
    //  In all Chilkat methods expecting a path, you pass either absolute or relative paths.
    success = CkPrivateKey_LoadAnyFormatFile(privKey,"rsaKeys/myTestRsaPrivate.pem",password);
    if (success == FALSE) {
        printf("%s\n",CkPrivateKey_lastErrorText(privKey));
        CkPrivateKey_Dispose(privKey);
        return;
    }

    rsa = CkRsa_Create();

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


    CkPrivateKey_Dispose(privKey);
    CkRsa_Dispose(rsa);

    }