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 />

Internally the getEncryptionKey() method calls the EncryptionKeyG<strong>en</strong>erator class’s validateStrongPassword()<br />

method and, if the password isn’t valid, throws an exception. The validateStrongPassword() method is a public<br />

method so that application code can check a password without calling the getEncryptionKey() method to avoid<br />

causing an error.<br />

Expand the password to 256 bits<br />

Adobe AIR 1.5 and later<br />

Later in the process, the password is required to be 256 bits long. Rather than require each user to <strong>en</strong>ter a password<br />

that’s exactly 256 bits (32 characters) long, the code creates a longer password by repeating the password characters.<br />

The getEncryptionKey() method calls the concat<strong>en</strong>atePassword() method to perform the task of creating the<br />

long password.<br />

var concat<strong>en</strong>atedPassword:String = concat<strong>en</strong>atePassword(password);<br />

The following is the code for the concat<strong>en</strong>atePassword() method:<br />

private function concat<strong>en</strong>atePassword(pwd:String):String<br />

{<br />

var l<strong>en</strong>:int = pwd.l<strong>en</strong>gth;<br />

var targetL<strong>en</strong>gth:int = 32;<br />

}<br />

if (l<strong>en</strong> == targetL<strong>en</strong>gth)<br />

{<br />

return pwd;<br />

}<br />

var repetitions:int = Math.floor(targetL<strong>en</strong>gth / l<strong>en</strong>);<br />

var excess:int = targetL<strong>en</strong>gth % l<strong>en</strong>;<br />

var result:String = "";<br />

for (var i:uint = 0; i < repetitions; i++)<br />

{<br />

result += pwd;<br />

}<br />

result += pwd.substr(0, excess);<br />

return result;<br />

If the password is less than 256 bits, the code concat<strong>en</strong>ates the password with itself to make it 256 bits. If the l<strong>en</strong>gth<br />

doesn’t work out exactly, the last repetition is short<strong>en</strong>ed to get exactly 256 bits.<br />

G<strong>en</strong>erate or retrieve a 256-bit salt value<br />

Adobe AIR 1.5 and later<br />

The next step is to get a 256-bit salt value that in a later step is combined with the password. A salt is a random value<br />

that is added to or combined with a user-<strong>en</strong>tered value to form a password. Using a salt with a password <strong>en</strong>sures that<br />

ev<strong>en</strong> if a user chooses a real word or common term as a password, the password-plus-salt combination that the system<br />

uses is a random value. This randomness helps guard against a dictionary attack, where an attacker uses a list of words<br />

to attempt to guess a password. In addition, by g<strong>en</strong>erating the salt value and storing it in the <strong>en</strong>crypted local store, it is<br />

tied to the user’s account on the machine on which the database file is located.<br />

Last updated 6/6/2012<br />

770

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

Saved successfully!

Ooh no, something went wrong!