How it works
You generate a key pair once. The private key stays on your server. The public key goes wherever it is needed. The two keys do opposite jobs, and the math makes it impractical to work out the private key from the public one.
There are two main uses. For encryption, anyone encrypts with the public key and only the private key holder can decrypt. For signatures, the private key holder signs and anyone with the public key can verify. License checks use signatures: see digital signature and the Ed25519 algorithm.
Why a public key can ship inside an app
The alternative is a shared secret, for example an HMAC key. Both sides hold the same value, so whoever holds one copy can create valid answers. A customer’s machine runs your app, so a secret inside it is a secret in the customer’s hands.
| Shared secret (HMAC) | Key pair (signatures) | |
|---|---|---|
| What the app holds | The secret itself | The public key |
| What a copy of it allows | Creating valid license answers | Checking license answers |
| Who can produce a valid answer | Anyone who extracts the secret | Only the private key holder |
| Fits best | Two servers that both trust each other | Software on machines you do not control |
Worked case. A vendor ships an app that checks HMAC(secret, payload). A reverse engineer finds the secret in the binary and writes a program that tags any payload, a keygen that never needs the vendor’s server again. With a key pair, the same reverse engineer finds only the public key. Verifying is all it can do. In a Node.js test, a payload changed after signing failed verification against the original signature, and nothing the verifier held could produce a new one.
What public keys do not protect
A public key does not protect the program that uses it. If an attacker can edit your binary, they can replace the public key with their own, or skip the check. That is a crack, and signatures cannot stop it. What they do stop is a forged server answer, such as a counterfeit “valid” response from a fake license server on the network.
Public-key versus symmetric cryptography
Symmetric cryptography, such as AES or HMAC, uses one key for both directions and is faster. Public-key cryptography uses two keys and solves distribution: you can tell the whole world the public key. Real systems often use both, for example a public-key exchange to agree on a symmetric key. A license check needs only the signature half.
How Clavem handles it
Each product has its own Ed25519 key pair. Clavem signs every license token with the private half, which it encrypts at rest and never shares. The public half, 32 raw bytes encoded as base64url, is on the product page in the dashboard and in public_key from GET /v1/admin/products. A token signed for one product does not verify under another product’s key, and the token’s pid field lets your app check that too. The offline verification guide has the code. The reasoning behind signing every answer is in why sign license responses.
Questions
Is it safe to put a public key inside an app?
Yes. A public key can only verify signatures, not create them. Extracting it from the app gives an attacker nothing they could not already read in your documentation.
Can someone replace the public key in my app?
Yes, if they patch the binary, and then they can sign tokens with their own private key. A public key protects the data in transit and at rest, not the program that checks it.