Home/Blog/Software Protection
Software ProtectionJuly 19, 202614 min read

qPapel C++ Native Protection SDK: Complete Integration Guide with qPapelLib.h & libsodium

Step-by-step developer tutorial demonstrating qpapel::Init(), QPCTX context creation, libsodium memory decrypting, and qpapel::Authenticate() using the official qPapelLib C++ SDK.

1. Official C++ SDK Architecture Overview#

Protecting Windows C++ native applications requires lightweight headers, cryptographic handshake verification, and zero external DLL dependencies. The official qPapel C++ SDK links against qPapelLib.lib and libsodium.lib to decrypt the core auth stub dynamically inside memory without leaving plaintext secrets on disk. Currently, qPapel Auth provides primary native protection libraries for C++ (MSVC 2019/2022 x64) and C# (.NET), with multi-language wrappers (Python, Rust, Go) planned on our roadmap.


2. Project Setup & Linking#

In your Visual Studio C++ solution, create the following directory structure:

code
YourProject/
├── Include/
│   └── qPapelLib.h
├── Lib/
│   ├── qPapelLib.lib
│   └── libsodium.lib
├── qPapelTools/
│   ├── qPapelPacker.exe
│   └── qPapelAuth64.dll   ← Download from papelship.com/dashboard/downloads
└── Source/
    └── main.cpp

Configure Visual Studio:

1. C/C++ → General → Additional Include Directories: Add $(ProjectDir)Include

2. Linker → General → Additional Library Directories: Add $(ProjectDir)Lib

3. Linker → Input → Additional Dependencies: Add qPapelLib.lib;libsodium.lib

4. C/C++ → Language → C++ Language Standard: Set to /std:c++17 or newer

5. Build Events → Post-Build: Set packer command:

cmd
"$(ProjectDir)qPapelTools\qPapelPacker.exe" --dll "$(ProjectDir)qPapelTools\qPapelAuth64.dll" --input "$(OutDir)$(TargetName)$(TargetExt)" --output "$(ProjectDir)dist\$(TargetName)_final_x64.exe"

> Important: Without running qPapelPacker.exe as a post-build step, your executable will not contain the encrypted qPapelAuth64.dll in its .qpdata section, and qpapel::Init() will fail at runtime.


3. Complete C++ Application Flow#

cpp
#include <iostream>
#include <string>
#include "qPapelLib.h"

#pragma comment(lib, "qPapelLib.lib")
#pragma comment(lib, "libsodium.lib")

int main() {
    // 1. Initialize core loader stub (decrypts qPapel core in memory)
    if (!qpapel::Init()) {
        std::cerr << "[ERROR] Core stub initialization failed." << std::endl;
        return 1;
    }

    // 2. Allocate Client Context Handle
    QPCTX ctx = qpapel::CreateContext();
    if (!ctx) return 1;

    // 3. Configure API Credentials (pk_ prefixed key from dashboard)
    qpapel::SetConfig(ctx, "pk_00000073_1381695181994e4ea94eabf54911520b", "", 0, "1.0.0");

    // 4. Run Local Memory Integrity Verification
    qpapel::CheckIntegrity(ctx);

    // 5. Establish TLS Connection
    if (qpapel::Connect(ctx)) {
        std::string key;
        std::cout << "Enter License Key: ";
        std::cin >> key;

        // 6. Authenticate Key against PapelShip Cloud
        char* token = qpapel::Authenticate(ctx, key.c_str());
        if (token != nullptr) {
            std::cout << "[AUTH SUCCESS] Token: " << token << std::endl;
            qpapel::FreeString(token);

            // 7. Fetch server-side encrypted string
            char* configValue = qpapel::FetchString(ctx, "123456789012", key.c_str());
            if (configValue) {
                std::cout << "[CONFIG] " << configValue << std::endl;
                qpapel::FreeString(configValue);
            }

            // 8. Start background heartbeat (30 sec interval)
            qpapel::StartHeartbeatThread(ctx, 30, []() {
                std::cerr << "[SECURITY] Heartbeat failed. Exiting." << std::endl;
                exit(0);
            });
        } else {
            char* err = qpapel::GetLastStatus(ctx);
            std::cerr << "[AUTH ERROR] " << (err ? err : "Invalid Key") << std::endl;
            if (err) qpapel::FreeString(err);
        }
    }

    qpapel::DestroyContext(ctx);
    return 0;
}

4. API Reference#

FunctionSignaturePurpose
qpapel::Init()bool Init()Decrypts core stub from .qpdata PE section into RAM
qpapel::CreateContext()QPCTX CreateContext()Allocates client session context handle
qpapel::SetConfig()void SetConfig(QPCTX, pk, ip, port, ver)Sets API key and app version
qpapel::CheckIntegrity()void CheckIntegrity(QPCTX)Verifies binary hash against dashboard uploaded hash
qpapel::Connect()int Connect(QPCTX)TCP + ECDH handshake + HWID registration
qpapel::Authenticate()char* Authenticate(QPCTX, key)Validates license key, returns JWT session token
qpapel::FetchString()char* FetchString(QPCTX, id, key)Fetches encrypted server-side string by 12-digit Access ID
qpapel::StartHeartbeatThread()bool StartHeartbeatThread(QPCTX, sec, cb)Background periodic encrypted ping with failure callback
qpapel::FreeString()void FreeString(char*)Frees SDK-allocated string buffers to prevent memory leaks
qpapel::DestroyContext()void DestroyContext(QPCTX)Releases context resources and closes connection

Protect your binaries with official qPapel C++ Auth.

PapelShip C++ & C# Software Protection

Protect Your C++ / C# Executables & Automate Sales

Launch your storefront, enforce HWID key activation, and accept non-custodial crypto checkout with PapelShip.

Tags:#qPapelLib#C++#libsodium#QPCTX#Authenticate#SDK