Offline-Lizenzaktivierungen (Pro)
Mit Enwikuna License Manager Pro kannst du deinen Kunden im Kundenkonto eine Offlineaktivierung für Lizenzen anbieten. Das kann sinnvoll sein, wenn deine Software nicht über eine Internetanbindung verfügt. Grundsätzlich läuft eine Offlineaktivierung wie folgt ab:
Damit die Offline-Lizenzaktivierung funktioniert, ist es wichtig, dass der Enwikuna License Manager Pro Encryptor eingerichtet ist. Hinweise zur Einrichtung findest du hier. Nachfolgend findest du zwei Codebeispiele in Node.js, welche dir bei deiner Implementierung helfen sollen.
Weitere Informationen zu Node.js findest du hier. Den nachfolgenden Code kannst du bei CodeConvert in eine beliebige andere Programmiersprache konvertieren lassen!
Aktivierungsdatei erstellen
Abschnitt betitelt „Aktivierungsdatei erstellen“const fs = require("fs");const crypto = require("crypto");const { Key, Crypto } = require("defuse-node");
const data = { license_key: "ABCD-EFGH-IJKL-MNOP", host: "E55E52A1-6320-43EE-A8E8-5648C7247716", product_uuid: "F200B966-53EB-4FD3-B548-09F18A11D75C", // Only required if you use the product UUID feature activation_timestamp: Math.floor(Date.now() / 1000), // Convert milliseconds to seconds};
// Convert the data object to a JSON stringconst jsonData = JSON.stringify(data);
console.log("JSON data:", jsonData);
// Create an SHA-256 hash objectconst sha256Hash = crypto.createHash("sha256");
// Update the hash object with the JSON datasha256Hash.update(jsonData);
// Get the hexadecimal representation of the hashconst sha256Hex = sha256Hash.digest("hex");
console.log("SHA-256 Hash:", sha256Hex);
// The Enwikuna License Manager Pro Encryptor key (can be found inside your wp-config.php file) never ever make your encryptor key accessible to the customer!// define( 'ELMP_ENCRYPTOR_KEY', 'def00000849d0ebcff36e52f06c4c39c7b6eb5605f6cd4f5c7c9bd5d72940aa280901c2e090e800a214d60e0cfa6c47a380661599c8f9ba0319482e6b18bed90ef713e82' );const encryptorKey = Key.loadFromAsciiSafeString( "def00000849d0ebcff36e52f06c4c39c7b6eb5605f6cd4f5c7c9bd5d72940aa280901c2e090e800a214d60e0cfa6c47a380661599c8f9ba0319482e6b18bed90ef713e82",);
// Encrypt the jsonData with the encryptor keyconst encryptedJsonData = Crypto.encrypt(jsonData, encryptorKey);
console.log("Encrypted JSON data:", encryptedJsonData);
// Write the encryptedJsonData to a TXT fileconst fileName = "sample-offline-license-activation.txt";const divider = "."; // Choose an appropriate divider
// Append the SHA-256 hash with the dividerconst dataToWrite = `${encryptedJsonData}${divider}${sha256Hex}`;
// Write to the filefs.writeFileSync(fileName, dataToWrite, "utf8");
console.log(`Encrypted data and SHA-256 hash appended to ${fileName}`);Eine aktuelle Beispieldatei mit dem Namen sample-offline-license-activation.txt findest du im Ordner sample-data innerhalb vom Enwikuna License Manager Pro.
Aktivierungszertifikat verarbeiten
Abschnitt betitelt „Aktivierungszertifikat verarbeiten“const fs = require("fs");const crypto = require("crypto");const { Key, Crypto } = require("defuse-node");
// Set the filenameconst filename = "sample-offline-license-activation.crt";
// Read the content of the fileconst fileContent = fs.readFileSync(filename, "utf8");
// Use regular expressions to extract the certificate content and hashconst match = fileContent.match( /-----BEGIN CERTIFICATE-----\s*([\s\S]*?)\s*\.\s*([\s\S]*?)\s*-----END CERTIFICATE-----/,);
if (match && match[1] && match[2]) { // Extracted certificate content and hash, remove all line breaks const certificateContent = match[1].replace(/\s/g, ""); const certificateHash = match[2].replace(/\s/g, "");
// Print the results console.log("Certificate content:", certificateContent); console.log("Certificate hash:", certificateHash);
// The Enwikuna License Manager Pro Encryptor key (can be found inside your wp-config.php file) never ever make your encryptor key accessible to the customer! // define( 'ELMP_ENCRYPTOR_KEY', 'def00000849d0ebcff36e52f06c4c39c7b6eb5605f6cd4f5c7c9bd5d72940aa280901c2e090e800a214d60e0cfa6c47a380661599c8f9ba0319482e6b18bed90ef713e82' ); const encryptorKey = Key.loadFromAsciiSafeString( "def00000849d0ebcff36e52f06c4c39c7b6eb5605f6cd4f5c7c9bd5d72940aa280901c2e090e800a214d60e0cfa6c47a380661599c8f9ba0319482e6b18bed90ef713e82", );
// Decrypt the encrypted jsonData with the encryptor key const jsonData = Crypto.decrypt(certificateContent, encryptorKey);
console.log("JSON data:", jsonData);
// Create an SHA-256 hash object const sha256Hash = crypto.createHash("sha256");
// Update the hash object with the JSON data sha256Hash.update(jsonData);
// Get the hexadecimal representation of the hash const sha256Hex = sha256Hash.digest("hex");
console.log("SHA-256 Hash:", sha256Hex);
if (sha256Hex !== certificateHash) { console.error("Invalid certificate hash. The file seems to be corrupt."); } else { const data = JSON.parse(jsonData);
console.log("Certificate data:", data);
// Now you can use the data to do your activation job. Maybe you want to validate the license key, the host or the certificate timestamp. }} else { console.error("Invalid certificate file format");}Eine aktuelle Beispieldatei mit dem Namen sample-offline-license-activation.crt findest du im Ordner sample-data innerhalb vom Enwikuna License Manager Pro.