License key generator
Generate random license keys for software you sell. Pick the format, how many you need, and copy them or download a CSV. It runs in your browser.
Each key has 123 bits of randomness: 25 characters from an alphabet of 31.
Keys are generated in your browser with the Web Crypto API and are never sent to a server. These are new keys for software you sell; they won't unlock anyone else's.
How to use the generator
Choose how many groups a key has and how many characters go in each group, and the keys update as you type. The default, five groups of five, gives you the familiar XXXXX-XXXXX-XXXXX-XXXXX-XXXXX shape.
- Characters to use. The default alphabet leaves out the characters people mix up when they retype a key: 0 and O, 1 and I and L. Use it unless you have a reason not to.
- Prefix. Optional. Something like
MYAPPat the start makes a key recognisable in a support email, and lets you tell products or editions apart at a glance. - How many keys. Up to 1,000 at a time. Download them as a CSV to import somewhere else.
One thing to be clear about: this makes new keys for software you sell. It can't produce a working key for someone else's product. A key only works if the software's maker has it on record, and a random string isn't on anyone's record.
What makes a good license key
A license key has two jobs: it has to be impossible to guess, and it has to be easy for a human to copy.
Impossible to guess comes down to randomness, measured in bits. Each character adds a few bits, depending on how big the alphabet is:
| Format | Alphabet | Randomness |
|---|---|---|
| 4 groups of 4 | 31 characters, no look-alikes | 79 bits |
| 5 groups of 5 | 31 characters, no look-alikes | 123 bits |
| 5 groups of 5 | 36 characters, A-Z and 0-9 | 129 bits |
| 4 groups of 4 | 16 characters, hexadecimal | 64 bits |
| 4 groups of 4 | Digits only | 53 bits |
Anything above about 80 bits can't realistically be guessed, as long as your server limits how fast someone can try keys. Digits-only keys are the weak ones: they need to be much longer to be safe.
Easy to copy is about the details:
- Break the key into groups of 4 or 5 with dashes. People read and type in chunks.
- Use one case. Uppercase is the convention, and your app should accept lowercase and convert it.
- Skip look-alike characters, so nobody emails you because they typed a zero where there's a letter O.
- Trim spaces and accept the key with or without dashes when a customer pastes it in.
And the randomness has to be real. Keys should come from a cryptographically secure random generator, which is what this page uses (crypto.getRandomValues). The ordinary random() function in most languages is predictable and shouldn't be used for keys.
Generating license keys in your own code
If you'd rather generate keys in your backend, these do the same thing as the tool above: five groups of five characters from the no-look-alikes alphabet, using each language's secure random source.
Python:
import secrets
ALPHABET = "23456789ABCDEFGHJKMNPQRSTUVWXYZ"
def license_key(groups=5, length=5):
return "-".join(
"".join(secrets.choice(ALPHABET) for _ in range(length))
for _ in range(groups)
)
JavaScript (Node.js):
import { randomInt } from "node:crypto"
const ALPHABET = "23456789ABCDEFGHJKMNPQRSTUVWXYZ"
function licenseKey(groups = 5, length = 5) {
const group = () =>
Array.from({ length }, () => ALPHABET[randomInt(ALPHABET.length)]).join("")
return Array.from({ length: groups }, group).join("-")
}
Ruby:
require "securerandom"
ALPHABET = "23456789ABCDEFGHJKMNPQRSTUVWXYZ".chars
def license_key(groups: 5, length: 5)
Array.new(groups) { Array.new(length) { ALPHABET[SecureRandom.random_number(ALPHABET.size)] }.join }.join("-")
end
C#:
using System.Linq;
using System.Security.Cryptography;
const string Alphabet = "23456789ABCDEFGHJKMNPQRSTUVWXYZ";
string LicenseKey(int groups = 5, int length = 5) =>
string.Join("-", Enumerable.Range(0, groups).Select(group =>
new string(Enumerable.Range(0, length)
.Select(position => Alphabet[RandomNumberGenerator.GetInt32(Alphabet.Length)])
.ToArray())));
A key on its own doesn't protect anything
This is the part that's easy to miss. A random key is just a string. It only becomes a license when something checks it, and there are two ways to do that.
Check it against a server. You store every key you've issued in a database. When a customer enters one, your app asks your server whether the key exists, whether it's been refunded, and how many devices it's already on. This is the common approach, and it's what lets you revoke a key or limit it to a number of devices. That device binding is called software activation.
Check a signature offline. Here the key (or a license file that goes with it) carries a cryptographic signature made with your private key. Your app holds the public key and can verify the license with no internet connection. It can't be forged without your private key. The trade-off is that you can't revoke it instantly, since the app never calls home.
Most products end up wanting both: an online check for activation and revocation, and a signed file so the app keeps working offline.
What doesn't work is the old trick of baking a checksum formula into the app, where any key matching a secret pattern is accepted. Once someone works out the pattern they can produce unlimited valid keys, and you can't tell them from real ones. That's exactly what a "keygen" for a pirated app is.
So besides generating keys, a working setup needs somewhere to store them, an endpoint that validates them, device limits, a way to deliver the key after payment, and a way to switch it off after a refund. You can build that yourself, or use a licensing service.
From a list of keys to an actual licensing system
If you're selling today and need keys right now, a batch from this page and a spreadsheet will get you going. It stops scaling at about the point where you're emailing keys by hand and can't remember which ones you've given out.
LicenseSeat does the whole loop. You connect your payment platform, and each sale generates a key and emails it to the customer. Your app validates it through an SDK, with device limits and offline validation included, and a refund revokes it. There's a licensing API if you'd rather call it directly.
Common questions about license key generators
Can this generate a license key for any software?
No. It generates new, random keys for developers to use in their own products. A key for existing software only works if that software's maker issued it, so a random key won't activate anything you didn't write.
Are these license keys unique?
In practice, yes. A five-by-five key from the default alphabet has 123 bits of randomness, so two keys colliding is so unlikely you can ignore it. Your database should still have a unique constraint on the key column, because that's free insurance.
How long should a license key be?
Long enough to carry about 80 bits of randomness or more. With letters and digits, that's 16 characters at the least, and 20 to 25 is a comfortable standard. Longer keys aren't more secure in any way that matters, and they're more annoying to type.
Is it safe to generate license keys in a browser?
Yes, with a tool that uses the Web Crypto API and doesn't send the keys anywhere. This page generates everything locally. If you want to be certain, you can turn off your internet connection after the page loads and it will still work.
What is the difference between a license key and a product key?
Nothing meaningful. License key, product key, serial number, serial key and activation code are all names for the same thing: a string a customer enters to prove they bought the software.
Do I need a server to use license keys?
To revoke keys, limit devices or see who's using what, yes. Without a server, the only safe option is a signed license that the app verifies offline, and you give up revocation. A hosted licensing service gives you the server without you having to run one.