How a keygen works
A keygen targets apps that decide whether a key is valid by arithmetic on the key itself, with no server involved. The check might be a checksum, a hash of the user name, or an HMAC with a secret inside the app. A reverse engineer reads the check in the binary and runs it backwards: generate random characters, then fix the last ones until the check passes.
Here is a deliberately weak check, a toy for illustration: a key is valid if its character values add up to a multiple of 97.
const ALPHABET = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
const isValid = (key) =>
[...key.replace(/-/g, '')].reduce((n, c) => n + ALPHABET.indexOf(c), 0) % 97 === 0;
A keygen for it is about a dozen lines. In a test run, 1,000 of 1,000 generated keys passed, for example 2F4DQ-DAG52-JYVEC-ZY1J5-HPWT6. Once such a keygen is published, every copy of the app is open.
Why random, server-checked keys defeat keygens
If the server decides validity by lookup, there is no algorithm to reverse. Clavem keys are 25 characters of Crockford base32, which is 125 random bits, and a key is valid only if it was issued. A worked example, with illustrative numbers: suppose 1,000,000 keys have been issued. A random guess matches one with probability 1,000,000 divided by 2^125, about 2.35 in 10^32. The License API also limits requests to 120 per minute per IP address, which is about 63 million guesses per year from one address. The chance of one success in that year is about 1.5 in 10^24.
How a crack works
A crack does not make keys. It changes the program, for instance by patching the branch that says “unlicensed” so it always goes the other way, or by replacing the public key the app uses to verify signed tokens with one the attacker controls and then signing their own tokens. Server-side keys and signed tokens do not stop this, because the attacker edits the code that does the checking.
Keygen versus crack
| Keygen | Crack | |
|---|---|---|
| What it attacks | The key-checking algorithm | The program’s control flow |
| Defeated by | Random keys validated on a server | Nothing complete |
| Usually survives a new app version | Yes, if the algorithm is unchanged | Often needs redoing, because it targets specific code |
| Cost of defence | Almost none | Rises quickly |
What a seller can do
- Never derive validity from the key’s own characters. Use random keys and ask a server, or verify a server signature.
- Do not rely on one
isLicensed()function. Check in several places and use the result later in the program, so a single patch is not enough. - Gate value that a cracked copy cannot get: updates, downloads, or features that run on your server.
- Treat obfuscation as a speed bump, not a lock.
- Accept that some copies will be cracked. See software piracy for which losses are cheap to prevent.
How Clavem handles it
Clavem generates random keys and checks them against its database, so there is no key algorithm in your app to reverse. Its release endpoint returns download links only for a valid license, so a cracked copy cannot fetch updates through your Clavem setup. Clavem does not protect the app binary itself. See license key security mistakes for what else to avoid.
Questions
Can a keygen produce keys for a server-checked license system?
Not usefully. If validity is decided by looking the key up on a server, a generated key is valid only if it happens to match one that was issued, which is astronomically unlikely for random keys of 125 bits.
Does verifying a signature offline stop cracks?
No. A crack edits the program that does the checking, so it can skip the check or swap in its own public key. A signature stops forged server answers, not an edited app.