- 🔐/🔓 License generation/validation using a secret key
- ⛓️💥 Custom, highly customizable license format
- 0️⃣ No dependencies
- 📦 Single header file
You can also find the list of examples in the example folder.
#include "drm.hpp"
int main() {
DV2::Internal::License license;
license.expirationTime = getTimeOffset(3600); // Expire in 1 hour
license.licenseLevel = 1; // Level of authorization, for example, 1 = free tier, 2 = premium, etc.
// Keep this secret! This is the key that will be used to generate and validate the license (can be of any length)
DV2::Internal::ByteArray secretKey = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C};
DV2::Internal::ByteArray licenseBytes =
DV2::Generation::generateLicense(license, secretKey);
// The type DV2::Internal::ByteArray is just an alias for std::vector<uint8_t>, which means you can encode it as a hex string,
// then show it to the user, or save it to a file, etc.
}#include "drm.hpp"
int main() {
DV2::Internal::ByteArray secretKey = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C};
DV2::Internal::ByteArray licenseBytes = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C};
try {
// NOTE: If you don't want to throw an exception when the license is expired, you can set the third parameter to false (default is true)
DV2::Internal::License parsedLicense =
DV2::Validation::parseLicense(licenseBytes, secretKey);
std::cout << "Parsed license:" << std::endl;
char timeBuffer[128];
std::tm *ptm = std::localtime(&parsedLicense.expirationTime);
std::strftime(timeBuffer, sizeof(timeBuffer), "%Y-%m-%d %H:%M:%S %Z", ptm);
std::cout << "\tExpiration Time (raw): " << parsedLicense.expirationTime
<< std::endl;
std::cout << "\tExpiration Time (str): " << timeBuffer << std::endl;
std::cout << "\tLicense Level: " << parsedLicense.licenseLevel
<< std::endl;
} catch (const std::exception &e) {
// The license is invalid
std::cerr << "Error parsing license: " << e.what() << std::endl;
}
}This project is licensed under the Apache License 2.0. More information can be found in the LICENSE file.