Jan 17

The Adobe AIR 1.1 runtime provides built-in encryption for the local store.

This feature can be used to secure sensitive information like usernames & passwords for web services.

The encrypted local store can be found at these locations on a user’s computer:

Windows: C:\Documents and Settings\<username>\Application Data\Adobe\AIR\ELS\

Mac OS: /Users/<username>/Library/Application Support/Adobe/AIR/ELS/

To use the AIR’s encrypted local store you will need to include the following packages:

1
2
3
import flash.data.EncryptedLocalStore;
 
import flash.utils.ByteArray;

The following code shows an example of encrypting a string and then storing it in the EncryptedLocalStore object. The strToEncrypt string needs to be converted into a ByteArray since the EncryptedLocalStore stores all of it’s data as a hash table that uses strings as keys and byte arrays for the data. In our example, we convert the strToEncrypt into a byteArray as the myByteArray variable using the ByteArray object’s writeUTFBytes method. We are now ready to save our data into the EncryptedLocalStore, which is done by using the EncryptedLocalStore’s setItem method. The setItem method takes a string parameter that it uses as the key for the hash table and then a byte array as the data that it needs to store.

1
2
3
4
5
6
7
var strToEncrypt:String = "Herman";
 
var myByteArray:ByteArray = new ByteArray();
 
myByteArray.writeUTFBytes(strToEncrypt);
 
EncryptedLocalStore.setItem("firstName", myByteArray);

To retrieve the encrypted data from the EncryptedLocaStore you will need to use the getItem method and the string key for the data that you want to retrieve from the hash table.

1
2
3
4
5
6
7
8
var storedValue:ByteArray = EncryptedLocalStore.getItem("firstName");
 
// get the string from the storedValue byte array and store in the strDecrypted variable
var strDecrypted:String = storedValue.readUTFBytes(storedValue.length);
trace(strDecrypted); // "Herman"
 
// read the string from the storedValue byte array
trace(storedValue.readUTFBytes(storedValue.length)); // "Herman"

More documentation can on the EncryptedLocalStore class can be found on Adobe’s site.

One Response to “Encrypting Local Data with Adobe AIR”

  1. Adobe Flash Access 2 – Ways to reset cached DRM Vouchers. - iheartair.com :: coderjun's thoughts Says:

    [...] For those that need some info on the Encrypted Local Store or where to find it on their system, here’s a blog post that discusses ELS along with the location of the ELS directory on Windows and Mac OS: http://www.digitaldogbyte.com/2009/01/17/encrypting-local-data-with-adobe-air/ [...]

Leave a Reply