Sample code for 30+ languages & platforms
C++ Requires Chilkat v11.0.0+

Open an RSA-OAEP and AES-128-CBC message

See more Email Object Examples

Read the output of the matching encryption example. Chilkat takes the algorithm parameters from the CMS envelope. Give it the recipient’s private key, then read the recovered subject and body only after decryption succeeds.

Chilkat C++ Downloads

C++
#include <CkEmail.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    CkEmail email;
    success = email.AddPfxSourceFile("recipient.pfx","PFX_PASSWORD");
    if (success != true) {
        std::cout << email.lastErrorText() << "\r\n";
        return;
    }

    success = email.LoadEml("oaep-encrypted.eml");
    if (success != true) {
        std::cout << email.lastErrorText() << "\r\n";
        return;
    }

    if (email.get_ReceivedEncrypted() != true) {
        std::cout << "The input has no S/MIME encryption layer." << "\r\n";
        return;
    }

    if (email.get_Decrypted() != true) {
        std::cout << "Could not decrypt with the available private keys." << "\r\n";
        return;
    }

    std::cout << "Subject: " << email.subject() << "\r\n";
    if (email.HasPlainTextBody() == true) {
        std::cout << email.getPlainTextBody() << "\r\n";
    }

    success = email.SaveEml("oaep-decrypted.eml");
    if (success != true) {
        std::cout << email.lastErrorText() << "\r\n";
        return;
    }

    std::cout << "Saved oaep-decrypted.eml." << "\r\n";
    }