13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with local SQL databases in AIR<br />

Understanding the EncryptionKeyG<strong>en</strong>erator class<br />

Adobe AIR 1.5 and later<br />

It isn’t necessary to understand the inner workings of the EncryptionKeyG<strong>en</strong>erator class to use it to create a secure<br />

<strong>en</strong>cryption key for your application database. The process for using the class is explained in “Using the<br />

EncryptionKeyG<strong>en</strong>erator class to obtain a secure <strong>en</strong>cryption key” on page 762. However, you might find it valuable to<br />

understand the techniques that the class uses. For example, you might want to adapt the class or incorporate some of<br />

its techniques for situations where a differ<strong>en</strong>t level of data privacy is desired.<br />

The EncryptionKeyG<strong>en</strong>erator class is included in the op<strong>en</strong>-source ActionScript 3.0 core library (as3corelib) project.<br />

You can download the as3corelib package including source code and docum<strong>en</strong>tation.You can also view the source<br />

code on the project site or download it to follow along with the explanations.<br />

Wh<strong>en</strong> code creates an EncryptionKeyG<strong>en</strong>erator instance and calls its getEncryptionKey() method, several steps are<br />

tak<strong>en</strong> to <strong>en</strong>sure that only the rightful user can access the data. The process is the same to g<strong>en</strong>erate an <strong>en</strong>cryption key<br />

from a user-<strong>en</strong>tered password before the database is created as well as to re-create the <strong>en</strong>cryption key to op<strong>en</strong> the<br />

database.<br />

Obtain and validate a strong password<br />

Adobe AIR 1.5 and later<br />

Wh<strong>en</strong> code calls the getEncryptionKey() method, it passes in a password as a parameter. The password is used as<br />

the basis for the <strong>en</strong>cryption key. By using a piece of information that only the user knows, this design <strong>en</strong>sures that only<br />

the user who knows the password can access the data in the database. Ev<strong>en</strong> if an attacker accesses the user’s account<br />

on the computer, the attacker can’t get into the database without knowing the password. For maximum security, the<br />

application never stores the password.<br />

An application’s code creates an EncryptionKeyG<strong>en</strong>erator instance and calls its getEncryptionKey() method,<br />

passing a user-<strong>en</strong>tered password as an argum<strong>en</strong>t (the variable password in this example):<br />

var keyG<strong>en</strong>erator:EncryptionKeyG<strong>en</strong>erator = new EncryptionKeyG<strong>en</strong>erator();<br />

var <strong>en</strong>cryptionKey:ByteArray = keyG<strong>en</strong>erator.getEncryptionKey(password);<br />

The first step the EncryptionKeyG<strong>en</strong>erator class takes wh<strong>en</strong> the getEncryptionKey() method is called is to check the<br />

user-<strong>en</strong>tered password to <strong>en</strong>sure that it meets the password str<strong>en</strong>gth requirem<strong>en</strong>ts. The EncryptionKeyG<strong>en</strong>erator class<br />

requires a password to be 8 - 32 characters long. The password must contain a mix of uppercase and lowercase letters<br />

and at least one number or symbol character.<br />

The regular expression that checks this pattern is defined as a constant named STRONG_PASSWORD_PATTERN:<br />

private static const STRONG_PASSWORD_PATTERN:RegExp =<br />

/(?=^.{8,32}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/;<br />

The code that checks the password is in the EncryptionKeyG<strong>en</strong>erator class’s validateStrongPassword() method.<br />

The code is as follows:<br />

public function vaidateStrongPassword(password:String):Boolean<br />

{<br />

if (password == null || password.l<strong>en</strong>gth

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!