Offline license activations (Pro)

Overview

With Enwikuna License Manager Pro, you can offer your customers offline activations on license activation within the customer account. This can be useful if your software does not have an Internet connection. Offline activation basically works as follows:

Offline license activation process

For offline license activation to work, it is important that the Enwikuna License Manager Pro Encryptor is configured. You can find instructions on how to set it up here. Below you will find two code examples in Node.js to help you with your implementation.

You can find more information about Node.js here. The following code can be converted into any other programming language at CodeConvert!


Create activation file

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 string
const jsonData = JSON.stringify(data);

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);

// 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 key
const encryptedJsonData = Crypto.encrypt(jsonData, encryptorKey);

console.log('Encrypted JSON data:', encryptedJsonData);

// Write the encryptedJsonData to a TXT file
const fileName = 'sample-offline-license-activation.txt';
const divider = '.'; // Choose an appropriate divider

// Append the SHA-256 hash with the divider
const dataToWrite = `${encryptedJsonData}${divider}${sha256Hex}`;

// Write to the file
fs.writeFileSync(fileName, dataToWrite, 'utf8');

console.log(`Encrypted data and SHA-256 hash appended to ${fileName}`);

You can find a current example file with the name sample-offline-license-activation.txt inside the folder sample-data within Enwikuna License Manager Pro.


Process activation certificate

const fs = require('fs');
const crypto = require('crypto');
const {Key, Crypto} = require('defuse-node');

// Set the filename
const filename = 'sample-offline-license-activation.crt';

// Read the content of the file
const fileContent = fs.readFileSync(filename, 'utf8');

// Use regular expressions to extract the certificate content and hash
const 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');
}

You can find a current example file with the name sample-offline-license-activation.crt inside the folder sample-data within Enwikuna License Manager Pro.