« Announcing FotoBooth 2 Pixel Bender Edition | Main | AIR Bootcamp »
Using Encrypted SQLite database in AIR 1.5 (from the cookbook)
| By Rich Tretola | November 18, 2008 | |
| 6,221 views |
The following example is covered within the new Adobe AIR 1.5 Cookbook Adobe AIR 1.5 now includes the ability to encrypt your SQLite database. The example below is a complete application. Be sure to use a compile with a minimum of the Flex 3.2.0.3266 SDK (or the latest stable build), set the application namespace to http://ns.adobe.com/air/application/1.5.
AIR 1.0 included SQLite as an embedded database within the runtime. To open a database when working with AIR 1.0 you would call the open() or openAsync() methods on the flash.data.SQLConnection whose signatures are as follows:
1 2 3 4 5 6 7 8 9 10 11 | open(reference:Object = null, openMode:String = "create", responder:Responder = null, autoCompact:Boolean = false, pageSize:int = 1024):void openAsync(reference:Object = null, openMode:String = "create", responder:Responder = null, autoCompact:Boolean = false, pageSize:int = 1024):void |
AIR 1.5 adds an optional additional argument of type ByteArray. Here are the new signatures:
1 2 3 4 5 6 7 8 9 10 11 12 13 | open(reference:Object = null, openMode:String = "create", responder:Responder = null, autoCompact:Boolean = false, pageSize:int = 1024, key:ByteArray = null):void openAsync(reference:Object = null, openMode:String = "create", responder:Responder = null, autoCompact:Boolean = false, pageSize:int = 1024, key:ByteArray = null):void |
OK, now lets talk about the example below. The only real difference is that we are going to supply a key when we open/create the database. The way the key is being created is through the use of a third party library called as3crypto. The key is then stored within the encrypted local store (ex: the keychain on Mac OS X).
Here is the chain of events:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | <?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="openDatabase()" height="150"> <mx:Script> <![CDATA[ import com.hurlant.crypto.prng.Random; private var storedKey:ByteArray; private var conn:SQLConnection; [Bindable] private var dbFile:File private function createRandomKey():ByteArray { var encryptionKey:ByteArray = new ByteArray(); var random:Random = new Random(); random.nextBytes(encryptionKey, 16); return encryptionKey; } private function openDatabase():void{ storedKey = EncryptedLocalStore.getItem("dbKey"); if(!storedKey) { storedKey = createRandomKey(); EncryptedLocalStore.setItem("dbKey", storedKey, false); } conn = new SQLConnection(); dbFile = File.applicationStorageDirectory.resolvePath("EncryptedDB.db"); conn.addEventListener(SQLEvent.OPEN, openHandler); conn.openAsync(dbFile,SQLMode.CREATE,null,false,1024,storedKey); } private function openHandler(event:SQLEvent):void { traceTxt.text += "The database was opened successfully \n\n"; traceTxt.text += dbFile.nativePath + "\n\n"; } ]]> </mx:Script> <mx:TextArea width="100%" height="100%" id="traceTxt"/> </mx:WindowedApplication> |
Here is the result:

Hope this helps. Be sure to check out the rest of the recipes in the new Adobe AIR 1.5 Cookbook
Topics: Adobe AIR | 8 Comments »







November 20th, 2008 at 2:36 am
For about eight years we have been helping clients to market their properties via the internet. About seven years we’ve been building our clients from scrath a custom flash presentation. Now more and more clients are more web savvy so that they’re wanting a more do it yourself type solution that would let them just log onto our site and then maybe pick from a number of templates that we could pre-define for them but then they could use those templates to build their own flash presentation. Do you have a suitable application to make this happen or any recommendation maybe?
Thanks,
Steve Alter
Reply to this comment
Akash Reply:
March 12th, 2010 at 3:52 pm
Hi, Steve,
I dont know if there is a do it yourself kind of technoology, but I my company does have resources which can possibly develop something to satisfy your needs…plz reply if you are interested
Reply to this comment
December 2nd, 2008 at 1:53 pm
thanks..
Reply to this comment
December 26th, 2008 at 11:51 am
Thanks for the valuable insight.
Reply to this comment
May 6th, 2010 at 8:30 am
blokunuz iyi ve güzel olmuş admin başariların devamını dilerim…
Reply to this comment
June 2nd, 2010 at 10:27 am
http://www.osmanoglunakliyat.com.tr
Reply to this comment
July 13th, 2010 at 11:38 am
so good!
Reply to this comment
July 15th, 2010 at 3:22 am
The regular season is a seventeen-week schedule during which each team has one bye week and plays sixteen games. This schedule includes six games against a team’s divisional rivals, as well as several inter-division and inter-conference games. http://www.nfljerseyse.com The season currently starts on the Thursday night in the first full week of September (the Thursday after Labor Day) and runs weekly to late December or early January.
Reply to this comment