// Psycho Key SDK — example integration // Build: see CMakeLists.txt or: // cl example.cpp /std:c++17 /EHsc /link winhttp.lib bcrypt.lib advapi32.lib crypt32.lib #include "psychokey.hpp" #include #include #include #include // Strings are obfuscated at compile time and decoded at runtime. // Replace with your product values from the panel. static const std::string API_BASE = PK_OBF("https://psycho-key.com"); static const std::string APP_SLUG = PK_OBF("psycho-key"); static const std::string API_SECRET = PK_OBF("REPLACE_WITH_64_HEX_PRODUCT_SECRET"); static const std::string APP_VERSION = PK_OBF("1.0.0"); // Optional: SHA-256 of your server certificate DER (hex). Empty = off. // Generate with: php tools/pin.php psycho-key.com static const std::string TLS_PIN = PK_OBF(""); int main() { psycho::Client client({API_BASE, APP_SLUG, API_SECRET, APP_VERSION, TLS_PIN, /*anti_debug=*/true, /*require_v2=*/true}); std::cout << "Psycho Key demo\n"; std::cout << "HWID: " << client.hwid() << "\n\n"; auto handshake = client.init(); if (!handshake.ok) { std::cout << "Handshake failed: " << handshake.code << " — " << handshake.message << "\n"; if (handshake.code == "OUTDATED_VERSION" && !handshake.download_url.empty()) { std::cout << "Update to " << handshake.latest_version << " at: " << handshake.download_url << "\n"; } return 1; } std::cout << "Server reachable. Product version: " << APP_VERSION << "\n"; std::cout << "Enter license key: "; std::string key; std::getline(std::cin, key); auto res = client.auth(key); if (!res.ok) { std::cout << "Access denied: " << res.code; if (!res.message.empty()) std::cout << " — " << res.message; std::cout << "\n"; if (res.code == "HWID_LIMIT" || res.code == "HWID_MISMATCH") { std::cout << "This machine is not bound to the key.\n"; std::cout << "Reset HWID and bind this machine? [y/N]: "; std::string answer; std::getline(std::cin, answer); if (answer == "y" || answer == "Y") { auto reset = client.reset_hwid(key); if (!reset.ok) { std::cout << "Reset failed: " << reset.code; if (reset.code == "RESET_COOLDOWN") { std::cout << " (retry after " << reset.retry_after << "s)"; } std::cout << "\n"; return 1; } res = reset; std::cout << "HWID reset. This machine is now bound.\n"; } else { return 1; } } else { return 1; } } std::cout << "\nLicense accepted.\n"; std::cout << " Status: " << res.license.status << "\n"; if (res.license.lifetime) { std::cout << " Expires: never (lifetime)\n"; } else { std::cout << " Expires: " << res.license.expires_at << " (" << res.license.days_left << " days / " << res.license.seconds_left << "s left)\n"; } std::cout << " HWID slots: " << res.license.max_hwids << "\n"; if (!res.variables.empty()) { std::cout << " Cloud variables received: " << res.variables.size() << "\n"; } std::cout << "\n"; std::cout << "Running protected application...\n"; // Heartbeat loop — keep the session alive / detect revocation / instant kick. for (int i = 0; i < 3; ++i) { std::this_thread::sleep_for(std::chrono::seconds(3)); auto hb = client.heartbeat(); if (!hb.ok) { std::cout << "Session invalidated: " << hb.code << " — shutting down.\n"; return 1; } std::cout << "Heartbeat OK (" << hb.license.seconds_left << "s left)\n"; } client.logout(); std::cout << "Done.\n"; return 0; }