Sample code for 30+ languages & platforms
Unicode C++

RSA Import Public Key from Certificate PEM

See more RSA Examples

Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkCertW.h>
#include <CkPublicKeyW.h>
#include <CkRsaW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkCertW cert;

    success = cert.LoadFromFile(L"qa_data/pem/mf_public_rsa.pem");
    if (success == false) {
        wprintf(L"%s\n",cert.lastErrorText());
        return;
    }

    CkPublicKeyW pubKey;
    cert.GetPublicKey(pubKey);

    CkRsaW rsa;
    rsa.UsePublicKey(pubKey);

    rsa.put_EncodingMode(L"base64");
    const wchar_t *encryptedStr = rsa.encryptStringENC(L"hello",false);
    wprintf(L"encrypted string = %s\n",encryptedStr);
    }