← All extensions

Native extension

KlugKeychain

com.klug.keychain.Keychain

NO APM NEEDED. Download and enjoy. It can’t get any simpler. Just update the Adobe AIR SDK. If you need help, we are here.

Secure key/value storage in the system keychain for AIR apps. Values survive uninstalling and reinstalling the app.

iOSmacOS In production From €9 / year · Buy

Overview

KlugKeychain stores small values, such as flags, tokens or IDs, in the keychain of iOS and macOS. Unlike normal app storage, the keychain keeps these values when the app is uninstalled and installed again.

That makes it a durable anchor for things an app needs to remember across reinstalls, for example whether a device has already used a free trial, or whether an account was deleted before.

KlugKeychain is in daily use in our apps, our proof of concept.

Features

  • Self-contained: one ANE, no core library or dependency ANEs to add
  • Store, read, check and remove values by key
  • Values survive uninstalling and reinstalling the app
  • Encrypted by the operating system in the system keychain
  • One API for iOS and macOS
  • Simple synchronous calls, no events to handle

Supported platforms

iOS arm64
macOS Apple silicon · Intel

On other platforms isSupported returns false, so the same code can stay in a cross-platform app.

On Android, KlugDeviceId provides the same reinstall-proof anchor: the Android device ID stays the same after the app is uninstalled and installed again.

Getting started

Add the extension to your application descriptor:

app.xml
<extensions>
    <extensionID>com.klug.keychain.Keychain</extensionID>
</extensions>

On macOS the app must be signed with a keychain access group entitlement. On iOS no extra entitlement is needed.

Code examples

Three complete flows. All calls are synchronous and return at once; values are strings. Full documentation →

1 · Check support and choose a fallback
Setup.as
import com.klug.keychain.Keychain;

var keychain:Keychain = Keychain.getInstance();

// iOS: always true.
// macOS: true only if the app is signed with a keychain access group entitlement;
//        the extension checks this with a test write.
// Android, Windows: false, and every call is a safe no-op.
if ( !keychain.isSupported )
    useLocalStorage();   // your app's fallback, e.g. a SharedObject
2 · Remember a free trial across reinstalls
Trial.as
const TRIAL_DAYS:Number = 7;

if ( keychain.has( "trialStarted" ) )
{
    var started:Number = Number( keychain.get( "trialStarted" ) );
    var days:Number = ( new Date().time - started ) / 86400000;
    if ( days > TRIAL_DAYS ) showPurchaseScreen();   // your app
}
else
{
    // stays in the keychain after the app is uninstalled and installed again
    keychain.set( "trialStarted", String( new Date().time ) );
}
3 · Store, read and remove a value
Account.as
// set() replaces an existing value; false = not stored
if ( !keychain.set( "accountId", accountId ) )
    trace( "keychain: value not stored" );

// get() returns "" when nothing is stored
var id:String = keychain.get( "accountId" );
if ( id == "" ) showSignIn();   // your app

// sign-out: remove what the app no longer needs;
// true also when the key was already gone
keychain.remove( "accountId" );

API overview

Keychain.getInstance()Returns the single instance.
isSupportedTrue on iOS. On macOS true when the app is signed with a keychain access group entitlement; false on other platforms.
set(key, value)Stores a string, replacing an existing one. Returns true on success; false if unsupported or key or value is null.
get(key)Returns the stored value, or an empty string if there is none.
has(key)True if a value is stored for the key.
remove(key)Removes the value. Returns true once the key no longer exists.
StorageGeneric password items of your app, readable after the first unlock of the device, also in the background.

Buy KlugKeychain

A yearly licence for one AIR application, with all updates for 12 months. After payment you receive the extension, the ActionScript library and the documentation by e-mail, usually within one business day. Licence and terms

Simple
€9 / year
  • Licence for one AIR application
  • All updates for 12 months
  • No support
Buy Simple
Standard
€39 / year
  • Licence for one AIR application
  • All updates for 12 months
  • Answer by e-mail within 7 days
Buy Standard
Priority
€79 / year
  • Licence for one AIR application
  • All updates for 12 months
  • Answer by e-mail within 48 hours
Buy Priority
Taxes are calculated at checkout by Link (Stripe). You enter the application ID of your AIR app during checkout.

Requirements

AIR SDK51.x (HARMAN)
iOSiOS 17 or later
macOSmacOS 11 or later
Signing (macOS)Keychain access group entitlement