A software license key generator creates a credential your app can verify to separate paying customers from unlicensed copies. There are two sound cryptographic approaches: high-entropy random keys validated against a server, or digitally signed claims verified locally offline. The best production systems combine both—random opaque keys for server authority and revocation, paired with short-lived Ed25519-signed leases for offline operation.

1. Random opaque keys (server-validated)

A random key carries no embedded metadata—it is simply an opaque identifier drawn from a cryptographically secure random generator (crypto.randomBytes in Node, secrets in Python; never Math.random). All meaning—order ID, product, device limit, expiry, and revocation status—lives authoritatively on your server.

Use at least 128–256 bits of entropy so brute-force guessing is infeasible even at massive request rates. Prefix keys (for example cpl_ for live keys and cpt_ for test keys) so support engineers and secret scanners can identify them immediately, and store a keyed hash in your database rather than plaintext.

2. Cryptographically signed keys (offline verification)

A signed license embeds structured claims (order ID, product, device public key, expiry) with an asymmetric digital signature—Ed25519 (RFC 8032) is fast, compact, and widely supported. Your server signs with its private key, and your app embeds only the public key so attackers cannot forge new licenses:

import { generateKeyPairSync, sign, verify } from 'node:crypto';

const { publicKey, privateKey } = generateKeyPairSync('ed25519');

function issue(claims: Record<string, unknown>) {
  const body = Buffer.from(JSON.stringify(claims)).toString('base64url');
  const sig = sign(null, Buffer.from(body), privateKey).toString('base64url');
  return body + '.' + sig;
}

function verifyLease(lease: string) {
  const [body, sig] = lease.split('.');
  if (!body || !sig) return null;
  if (!verify(null, Buffer.from(body), publicKey, Buffer.from(sig, 'base64url'))) return null;
  const claims = JSON.parse(Buffer.from(body, 'base64url').toString());
  return claims.exp * 1000 > Date.now() ? claims : null;
}

The limitation of standalone static signed keys is revocation: without a server check, a refunded or charged-back key remains valid until its embedded expiry.

3. The hybrid pattern: online activation + signed offline leases

Combining both models gives you instant revocation and rock-solid offline reliability:

  1. When payment settles, your server issues a high-entropy random license key.
  2. When a user activates the app on a machine, the app generates a local Ed25519 device keypair and signs the activation request (proof of possession).
  3. Your license server validates the key, enforces device limits and refund/dispute status, and returns a time-limited Ed25519-signed offline lease bound to that exact device public key.
  4. While offline, the app verifies the lease locally using your pinned issuer public key. When back online, it quietly renews the lease—automatically enforcing revocations, chargebacks, or policy changes.

Why a bare key generator is never enough

Generating a random string takes five lines of code. Production software licensing requires everything around it: idempotent issuance tied to verified payment settlement (never duplicate keys on webhook retries), device management and self-deactivation in a buyer portal, instant revocation on refunds and chargebacks, release-channel gating, and migration paths for legacy apps.

How CopperPouch handles licensing end to end

CopperPouch implements this hybrid architecture out of the box—issuing 256-bit prefixed keys (cpl_ / cpt_) at verified settlement, storing keyed hashes plus encrypted recovery copies for one-time portal reveal, enforcing policy-driven device limits and optional strict hardware commitments, and signing offline leases up to 30 days verified with our official TypeScript SDK. Migrating from Lemon Squeezy? CopperPouch also imports existing keys and exposes a drop-in compatible API—see the license key migration guide and our software licensing overview.

References