Blog

How to check a license key in your Mac app offline

Short answer: To check a license key in your Mac app offline, sign each license on your server with Ed25519, then verify the signature in the app with CryptoKit and the matching public key. A paying customer stays unlocked without a network call, including on a plane or on a Mac that is offline. Verify the signature and the expiry at launch, and again where the paid feature runs, rather than caching a single isLicensed() flag. Working Swift and Python samples are open source in fortifiexyz/offline-license-check.

Why a signed license beats a shared serial

A shared serial list, or a secret compiled into the app, can be copied out of the binary. Anyone who has that secret can invent keys your app will accept, or share one serial widely. AI tools make that read faster than it used to be.

A signed license works the other way around. Your server holds a private key and signs a small payload: the customer's email, the product name, and an expiry. The app ships the public key and uses it to verify the signature. The public key cannot issue a new license.

The license string

Sign the raw payload bytes. Then ship the payload and the signature as standard Base64, joined by a period:

base64(payload) + "." + base64(signature)

The payload is JSON, for example:

{"email":"[email protected]","product":"MyApp","expiry":"2027-11-17T00:00:00Z"}

Leave the payload machine-agnostic unless you have a clear reason to bind a device, so the same license still works on a replacement Mac.

The app must verify the exact bytes that were signed, then parse the JSON. Do not rebuild or pretty-print the JSON before checking the signature.

Verify the license in Swift with CryptoKit

CryptoKit exposes Ed25519 as Curve25519.Signing. Create the public key with Curve25519.Signing.PublicKey(rawRepresentation:) and verify with isValidSignature(_:for:). Embed the 32-byte public key in the app as a Base64 string.

import CryptoKit
import Foundation

struct LicensePayload: Codable {
    let email: String
    let product: String
    let expiry: String
}

enum LicenseStatus {
    case valid(LicensePayload)
    case malformed
    case badSignature
    case expired
    case wrongProduct
}

func verifyLicense(
    _ license: String,
    publicKeyData: Data,
    product: String,
    now: Date = Date(),
    grace: TimeInterval = 14 * 24 * 60 * 60
) -> LicenseStatus {
    let parts = license.split(
        separator: ".",
        maxSplits: 1,
        omittingEmptySubsequences: false
    )
    guard parts.count == 2,
          let payload = Data(base64Encoded: String(parts[0])),
          let signature = Data(base64Encoded: String(parts[1]))
    else {
        return .malformed
    }

    guard let publicKey = try? Curve25519.Signing.PublicKey(
            rawRepresentation: publicKeyData
          ),
          publicKey.isValidSignature(signature, for: payload)
    else {
        return .badSignature
    }

    guard let claims = try? JSONDecoder().decode(
            LicensePayload.self,
            from: payload
          )
    else {
        return .malformed
    }

    if claims.product != product {
        return .wrongProduct
    }

    let formatter = ISO8601DateFormatter()
    formatter.formatOptions = [.withInternetDateTime]
    guard let expiry = formatter.date(from: claims.expiry) else {
        return .malformed
    }

    if expiry.addingTimeInterval(grace) < now {
        return .expired
    }

    return .valid(claims)
}

Call this at launch, and again where the paid feature runs, passing the stored license string rather than a cached Bool.

Sign the license on the server

Keep the private key on the server, never in the app. This Python snippet signs the raw payload bytes and prints a license string in the format above:

import base64
import json
from cryptography.hazmat.primitives.asymmetric.ed25519 import (
    Ed25519PrivateKey,
)
from cryptography.hazmat.primitives.serialization import (
    Encoding,
    PublicFormat,
)

# Keep this private key on the server.
private_key = Ed25519PrivateKey.generate()
public_key_b64 = base64.b64encode(
    private_key.public_key().public_bytes(Encoding.Raw, PublicFormat.Raw)
).decode("ascii")

payload = json.dumps(
    {
        "email": "[email protected]",
        "product": "MyApp",
        "expiry": "2027-11-17T00:00:00Z",
    },
    separators=(",", ":"),
).encode("utf-8")

signature = private_key.sign(payload)
license_key = (
    base64.b64encode(payload).decode("ascii")
    + "."
    + base64.b64encode(signature).decode("ascii")
)

print("public_key:", public_key_b64)
print("license:", license_key)

Generate the key pair once and store the private key in your server's secret store. If it leaks, you will have to ship a new public key in an update.

Where to store the license

After the customer activates a license, write the license string somewhere durable. Application Support (~/Library/Application Support/YourApp/) is simple and survives app updates. The Keychain is a reasonable extra step if you would rather not leave a loose file. Neither hides it from someone who already uses the Mac.

Check at launch and where the paid feature runs

A single isLicensed() Bool is a small, obvious patch target. Check in more than one place:

  1. At launch, verify the signature, the product name, and the expiry, then decide whether to show the paid UI.
  2. Where the paid feature actually runs (an export or a render), read the stored license again and verify it again.

If either check fails, refuse that work.

Give honest offline users a little grace

Paying customers will go offline or have a slightly wrong clock. If the signature is valid and the expiry has just passed, allow a short grace window (for example 14 days) and show a renewal reminder. You can still recheck with your server in the background so a refunded license does not stay valid forever. Keep that recheck from becoming a hard gate at launch.

What a signed license does not stop

A signed license rejects forged keys. It does not stop a patch that skips the check. If someone flips the branch that unlocks the paid feature, the signature never runs. Harden the shipped build so the check is harder to find and patch, and watch public listings after you ship.

A signed license also does not stop a paying customer from sharing a real key. If you think your keys or serials are being passed around, see How to find leaked license keys and cracked copies of your app, then revoke the real ones on your server so your background recheck can turn them off.

See How to protect your Mac app from AI reverse engineering and How to stop your Mac app from being cracked.

How Fortifie fits

Fortifie hardens Mac and JavaScript builds against AI reverse engineering and cheap static reads, then watches for clones and cracks. You keep your Developer ID. You review the hardened build. Nothing ships without you.

In our tests on two small Mac license apps we own, standard tools and a one-shot AI pass recovered the secret and the license key from unprotected and stripped builds, and a short script unlocked the paid feature with a wrong key. From the Fortifie builds those tools recovered nothing, a debugger aborted before decrypt, and a four-round AI agent recovered nothing from the C build. On Swift, one model recovered nothing in four rounds and the other hit an API refusal. Size was about 2.4x (C) and 2.8x (Swift), with about 2-3 ms added at launch. After a valid key the original code still runs in memory, so a determined attacker who defeats the anti-debug and dumps memory can still recover it. C++ Mac apps are not supported yet. These are our own small test apps, not a broad benchmark. Method and tables: How we test.

Hardening raises attacker cost and time. It does not make cracking or reverse engineering impossible.

After you ship, the free check at fortifielabs.com/cracked searches public listings. It is a search, not proof.

Solo is $39/month and Studio is $149/month, and new monthly plans are 50% off the first month. Business is custom. See pricing.

The code from this guide is open source: fortifiexyz/offline-license-check.

Frequently asked questions

How do I check a license key in my Mac app offline?

Sign the license on your server with Ed25519, embed the public key in the app, and verify the signature, the product name, and the expiry with CryptoKit. No network call is required.

Can I verify a Mac app license without calling a server at launch?

Yes. Once the app has the signed license string and the public key, CryptoKit can verify the signature locally. You can still recheck with your server in the background so a refunded license does not stay valid forever. Keep that recheck from becoming a hard gate at launch.

Why is a signed license stronger than a shared serial?

A shared serial, or a secret compiled into the app, can be copied out of the binary and reused. A signed license works the other way around: the server holds the private key and the app ships the public key. The public key can verify a license and cannot issue a new one.

Does a signed license stop someone from patching out the check?

No. A signed license rejects forged keys. It does not stop a patch that skips the check. If someone flips the branch that unlocks the paid feature, the signature never runs. Spread the check across launch and the paid feature, harden the shipped build, and watch public listings after you ship. Hardening raises attacker cost and time. It does not stop a determined attacker. Methods and limits: How we test Fortifie.

Will hardening break offline licenses, and where should I store the key?

Hardening does not require a network call at launch. In our tests, a valid key still unlocked the Fortifie builds. After a valid key, the original code still runs in memory, so a determined attacker who defeats the anti-debug and dumps memory can still recover it. C++ Mac apps are not supported yet. After the customer activates, write the license string somewhere durable. Application Support (~/Library/Application Support/YourApp/) is simple and survives app updates. The Keychain is a reasonable extra step if you would rather not leave a loose file. Neither hides it from someone who already uses the Mac.

Related

How to protect your Electron app's source code.

How to protect your Mac app from AI reverse engineering.

How to stop your Mac app from being cracked.