Encrypted Local Storage
Using Encrypted Local storage for your AIR application has its own pros and cons. One should take enough care for which purpose it is being used. Although this feature is supported by most of the OS, still it is not available for the Mobile applications.
EncryptedLocalStore isSupported is the property you can use to check whether ELS is supported or not.
ELS is strongly recommended to use as a private cache for the application. It should conatain only those information which needs to be secured from other users of the system or for Application specific user information.
ELS data can get lost due to few reasons like
- Change in the Publisher ID as a result of the update.
- User could uninstall the application & delete the ELS data.
How to storr file inELS ?
I am initiating the process by clicking let’s say “save” button.
protected function saveButton_clickHandler( event:MouseEvent ):void
{
resultLabel.text = "";
EncryptedLocalStore.reset();
var file : File = File.documentsDirectory;
file.browseForOpen("Save file to Encrypted Location");
file.addEventListener(Event.SELECT,saveFile);
}
Now the “saveFile” function will work after the file has been selected by the user.
The target property will give us the instance of the File class, selected by user. Next, it creates an instance of the FileStream class that will be used to stream the bytes from the file into a ByteArray. Next, the filename is stored because it will be used as the key for the Encrypted Local Store. Finally, the value is stored in the Encrypted Local Store.
protected function saveFile( event:Event ):void
{
var file = File(event.target);
var stream :FileStream = new FileStream();
var fileData : ByteArray = new ByteArray();
stream.open(file,FileMode.READ);
stream.readBytes(fileData,0,file.size);
stream.close();
fileName = file.name;
EncryptedLocalStore.setItem(fileName,fileData);
resultLabel.text = "File saved to encrypted local store"
}