KeyAuth
Sign in

C++ SDK reference

C++17 for Windows, linking only against system libraries. No vcpkg, no OpenSSL, no package manager.

Building

Download the archive from the SDK tab; it already contains keyauth_config.h with your endpoint, application id, version and masked secret.

bat
build.bat            :: optimised
build.bat debug      :: debug

cmake -B build -S . -A x64
cmake --build build --config Release

Requires Visual Studio 2019 or newer with the C++ workload, and Windows 7 or newer at runtime. Links against bcrypt, winhttp, crypt32 and advapi32. Omitting advapi32 fails at link time because of the registry reads used for MachineGuid.

Lifecycle

bool initialize()

Checks the version, evaluates blacklists and opens a session. Call this first, every run.

Returns: false on any failure; read error_code()

bool login(const std::string& key, const std::string& hwid = {})

Validates the key, binds the device and populates license(), release() and files(). Leave hwid empty to let the SDK compute it from your configured sources.

Returns: false if the key is refused

bool validate()

Heartbeat. Extends the session and re-checks the key, so a ban takes effect here. Call it every few minutes and treat a failure as a reason to shut down.

Returns: false when the session or key is no longer good

bool logout()

Closes the session immediately, freeing a concurrent session slot.

Files

bool download(const std::string& key, std::vector<std::uint8_t>& out)

Resolves the file behind a JSON key. If it arrived inline with the login it is decoded from memory, otherwise chunks are fetched. Either way the result is decompressed and verified against its size and SHA-256. On failure out is cleared rather than left with partial bytes.

bool refresh_files(bool request_inline = false)

Re-reads the active release without logging in again. Useful for a long running client that should pick up a new release you just activated.

const std::vector<FileInfo>& files() const

The files in the active release. Also find_file(key), which returns nullptr when absent.

Variables, logging, state

MemberPurpose
variable(name, out)Fetch an encrypted application variable.
log(message, level)Write into your activity log. Levels: info, warning, error, security, debug.
self_ban(reason)Ban the current key. Only works if you enabled it per application.
authenticated()Whether login succeeded and the session is still open.
license()Level, expiry, uses, masked preview.
release()Version, notes and file count of the active release.
session_expires_in()Seconds until the session lapses.
server_time_offset()Difference between the local and server clock, in seconds.
error_code(), error_message()Set on every failure. Match on the code.

Free functions

FunctionPurpose
keyauth::hardware_id(sources)The digest this machine reports. Handy for support.
keyauth::cpu_descriptor()The raw CPUID string, before hashing.
keyauth::library_version()SDK version.

Client is not thread safe and is deliberately non copyable. Use one instance per thread, or serialise access yourself.

Do not weaken the failure path

The SDK returns false and refuses to treat an unsigned response as success. If you rewrite the failure handling to be lenient, a man in the middle can inject a plaintext “login ok”. Keep verify_tls on in production too.