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

Load PFX/P12 from a Base64 Encoded PFX File

See more PFX/P12 Examples

Demonstrates how to call LoadPfxEncoded.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkBinDataW.h>
#include <CkPfxW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkBinDataW bd;

    success = bd.LoadFile(L"qa_data/pfx/cert_test123.pfx");
    if (success != true) {
        wprintf(L"Failed to load PFX file.\n");
        return;
    }

    // Get the bytes contained in the PFX in base64 format:
    const wchar_t *strBase64 = bd.getEncoded(L"base64");

    // The base64 looks like this:  "MIIbEAIBAzCCGswGCSqGSIb3DQEHAaCCGr0Eghq5MIIatTCCBg..."
    wprintf(L"%s\n",strBase64);

    CkPfxW pfx;

    // Load the PFX from the base64 string
    const wchar_t *password = L"test123";
    success = pfx.LoadPfxEncoded(strBase64,L"base64",password);
    if (success != true) {
        wprintf(L"%s\n",pfx.lastErrorText());
        return;
    }

    wprintf(L"success\n");
    }