On this page

Guide

How to Add License Keys to a Flutter App

The Keyfern Dart SDK is one file for Flutter and Dart apps on iOS, Android, macOS, Windows and Linux. Its only dependency is the pure-Dart cryptography package.

Every answer from Keyfern is signed with your product’s Ed25519 key. The app embeds only the public key, checks the signature and a random nonce on every answer, and keeps the last signed answer so it can start offline during the lease you set. Flutter web is not supported.

Step 1: Add the SDK

Download keyfern.dart into your lib/ folder and add its dependency (plus path_provider for the cache folder):

flutter pub add cryptography path_provider

On macOS the app needs the com.apple.security.network.client entitlement to reach the server.

Step 2: Activate and verify

import 'package:path_provider/path_provider.dart';
import 'keyfern.dart';

final dir = (await getApplicationSupportDirectory()).path;
final kf = Keyfern(
  product: 'prod_xxx',
  publicKey: '<public key from the dashboard>',   // safe to embed in your app
  storage: FileStorage('$dir/keyfern.license'),
);

try {
  final lic = await kf.activateOrCached(userKey, await Keyfern.installId('$dir/keyfern.id'));
  if (lic.has(1)) unlockPro();                     // feature flag F1
} on KeyfernException catch (e) {
  showLicenseProblem(e.code);                      // blocked, expired, invalid_key, machine_limit, lease_expired...
}

The cached license is a signed answer, so it needs no encryption: editing it breaks the signature. Offline starts are refused once lease_until has passed, or when the clock was set back more than one hour.

Machine id

On iOS and Android use Keyfern.installId(path), a random id kept in the app folder, or your own device id. On Windows, macOS and Linux, Keyfern.machineId() returns a stable hashed id of the computer, the same value the Python, JavaScript and Kotlin SDKs compute.

App Store and Google Play rules

Apps sold through the App Store or Google Play must sell digital content and subscriptions inside the app with Apple’s in-app purchase (StoreKit) or Google Play Billing. Keyfern keys on mobile are for licenses bought where the store rules allow it: business and enterprise apps, companion apps of software the customer already bought on the web, and licenses that cover several devices and platforms. Check the App Store Review Guidelines (payments) and the Google Play payments policy for your case before you ship.