DEV Community

Fortifie
Fortifie

Posted on Originally published at fortifie.xyz

How to check a license key in your Mac app offline

Short answer: Sign each license on your server with Ed25519, then verify it in the app with CryptoKit and the matching public key. Honest customers stay unlocked offline, because the check does not need a network call. Verify the signature and the expiry at launch and again where the paid feature runs, not in a single isLicensed() flag.

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":"customer@example.com","product":"MyApp","expiry":"2027-11-17T00:00:00Z"}
Enter fullscreen mode Exit fullscreen mode

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)
}
Enter fullscreen mode Exit fullscreen mode

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": "customer@example.com",
        "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)
Enter fullscreen mode Exit fullscreen mode

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.

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 fortifie.xyz/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.

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 and expiry with CryptoKit. No network call is required.

Why is a signed license stronger than a shared serial?
A shared serial or an embedded secret can be copied out of the binary and reused. A 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 patch that skips the check still unlocks the paid feature. Spread the check, harden the build, and watch public listings.

Will hardening break offline licenses?
No. Hardening does not require a network call at launch. In our tests, a valid key still unlocked the Fortifie builds.

Where should I store the license on the Mac?
Application Support is simple and survives app updates. The Keychain is a reasonable choice if you do not want a loose file.

Originally published on fortifie.xyz by the Fortifie team.

Top comments (0)