Start from what you cannot stop
Whoever controls a computer controls the program running on it. A cracker does not need to guess your keys or fool your server. They can change the app’s own check so that it always answers “licensed”. A license check in your app is therefore a speed bump, not a wall.
That sounds bleak, but it points to a better plan. Spend your effort where it changes behaviour, and do not spend honest buyers’ goodwill on measures that only slow a determined attacker. There are two groups of people who use software without paying. Most are casual: a friend passes on a key, a key leaks on a forum, a trial never ends. A few are determined and will crack anything. You can influence the first group cheaply. For the second, you cannot, and you should not hurt customers trying.
I will not quote piracy statistics here. Figures in this area are usually self-reported by vendors, and none I could verify are specific enough to size your problem. Measure your own: how many keys sit at their device limit, and how many activations come from places you do not expect.
A layered approach
Each layer below is cheap, and each stops one specific thing. The right column is the cost to a buyer who did nothing wrong.
| Layer | What it stops | Cost to an honest buyer |
|---|---|---|
| Random keys checked on the server | Made-up keys and key generators for your format. | None. |
| Device limit | One purchase running on many unrelated computers. | A seat to free after a reinstall or a new laptop. |
| Signed tokens, verified in the app | A fake server or hosts-file trick that answers “valid”. | None. |
| Revocation on refund and chargeback | Keys that were refunded and then kept. | None, unless you refund by mistake. |
| Periodic online refresh with a grace window | A revoked key working forever offline. | A prompt to connect once after the window. |
| Obfuscation, anti-tamper, code signing | Casual patching, and tampered downloads. | Build complexity, support for false positives. |
| Value that lives on your server | Cracked copies: updates, sync and downloads need a real license. | None. |
Read the table as a list of trade-offs. Random keys, signed tokens and revocation cost the buyer nothing and stop the common cases. The last layer is the only one that a cracked binary cannot reproduce.
Why a signed token is the layer that matters most
An unsigned check looks like this: the app calls your server, reads valid: true, and carries on. An attacker who redirects that hostname to their own machine can answer valid: true for any key. A signed token closes that hole. The server signs a small statement with a private key that never leaves it, and the app verifies the signature with the public key it ships. A fake server cannot produce a signature the app accepts. The attacker then has to change the app itself, which is harder. Why signing responses matters shows this in a runnable demonstration.
Fail open for a fixed window
An always-online check turns every outage, plane flight and corporate firewall into a lockout. Buyers do not blame their network. They blame you, and some ask for a refund.
A better rule has a window. The app calls the server at launch. If the server answers, the app uses the answer. If it does not, the app trusts the last signed token while that token is fresh. In Clavem, a token carries refresh_by, which is the issue time plus 14 days. After that, the app asks the customer to connect once. A revoked license therefore stops working on every device within 14 days at most, and an honest customer on a long trip is not interrupted. See offline license checks explained.
| App state | What the app does |
|---|---|
Server answers valid: true |
Store the new token, run. |
Server answers valid: false |
Store the token, tell the buyer why using the error text, keep the key, because a renewal can revive it. |
| Server answers 404 | The key or the device is unknown. Ask for the key again. |
No answer, token verifies and refresh_by is in the future |
Run. |
No answer and refresh_by has passed |
Ask the buyer to connect once. |
What does not work
Obfuscation as the only protection. It changes how long it takes to read the code and does nothing about the patched check. It also makes crash reports harder to read.
Locking the screen when the network fails. You punish the customers who pay and do not slow the ones who patch the app.
Heavy digital rights management. Kernel drivers, hidden background services and hardware dongles give you support tickets, security concerns and bad reviews. A small team cannot maintain them.
Raw hardware ids sent to the server. They are personal data in some jurisdictions and they leak if your server does. Send a hash, or see machine fingerprinting pitfalls.
A list of leaked keys shipped inside the app. The list grows forever. Revoke on the server instead.
A worked cost estimate
Here is an illustration with stated assumptions. It is not a measurement. Suppose you sell 1,000 licenses at $49, and a protection measure locks out some honest buyers by mistake. Suppose each lockout takes 15 minutes of support, and one lockout in five ends in a refund.
| False lockout rate | Lockouts | Support time | Refunds | Revenue lost to refunds |
|---|---|---|---|---|
| 1% | 10 | 150 minutes | 2 | $98 |
| 0.1% | 1 | 15 minutes | 0.2 | about $10 |
On these assumptions, a measure with a 1% false-positive rate costs about two and a half hours and $98 per 1,000 buyers, before counting the reviews and the lost trust. It pays for itself only if it brings in more than two extra $49 sales per 1,000 buyers, which is hard to demonstrate. Change the numbers to your own. The point is to make the trade explicit before you add a check that can lock someone out.
Trials are the other leak
An expired trial that keeps running is one way people end up with an unlicensed copy. A trial that is only a date stored in a file can be reset by deleting the file or changing the clock. You can accept that, or move the trial to the server: issue a time-limited trial license, so the end date is a signed exp claim that the user cannot edit. Either way, decide on purpose. Free trial versus freemium compares the two designs.
Three numbers worth tracking
Before you add any protection, find out whether you have a problem. Three counts, all available from your own licensing data, tell you more than a general statistic:
- Licenses at their device limit. A few are normal. A rising share suggests sharing.
- Activations per license over time. One key activated and removed many times is a buyer moving between computers, or someone testing a key on many machines.
- Validation requests from unexpected places, if your licensing service exposes them, and the rate-limit rejections on your own endpoints.
If none of these moves, spend the time on the product. If one does, tighten that specific layer, such as lowering the limit for a product that sells to teams, instead of adding a new check that everyone feels.
Revocation and refunds
A refund is the cleanest anti-piracy tool you have, because it ends the license for exactly the person who asked. In Clavem, a full refund of a Stripe payment disables the licenses from that order. A partial refund changes nothing. Devices that are offline keep working until their token needs refreshing, at most 14 days.
If a key leaks on a forum, you can disable it in the dashboard, or with PATCH /v1/admin/licenses/:id and { "disabled": true }. Honest buyers who shared that key by accident will write to you, and you can issue them a new one.
Put the value on the server
The check that a cracker cannot copy is the one whose result they cannot fabricate. Updates are the clearest example. The release endpoint returns the version number to anyone, and returns release notes and signed download links only for a valid license. A pirated copy can run, but it does not receive the next build. Cloud sync and server-side features work the same way.
Doing this with Clavem
Clavem covers the layers that belong to a licensing service: random 25-character keys checked on the server, a per-product device limit, Ed25519-signed tokens, revocation on full refunds, a 14-day refresh_by window, and a license-gated releases endpoint. It does not do obfuscation, anti-tamper or code signing, and you should not expect a licensing service to. Code signing is covered in code signing certificates explained. The offline verification docs have the verification code.
Questions
Can software piracy be stopped completely?
No. Code that runs on a buyer's computer can be changed by whoever controls that computer. The practical goal is to make paying easier than cracking, to stop casual key sharing, and to avoid punishing honest customers.
Is obfuscation worth it?
It raises the effort of reverse engineering a little and has costs: build complexity, harder crash reports and sometimes antivirus false positives. Treat it as one cheap layer, never as the only defence.
Should an app refuse to start when it is offline?
Rarely. A short fail-open window, such as trusting a recently signed token for 14 days, keeps honest users working on a plane and still lets a revoked key stop working within that window.