as3corelib 0.1.0 → 0.85.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -4
- data/Gemfile.lock +7 -4
- data/README.textile +20 -10
- data/Rakefile +32 -2
- data/as3corelib.gemspec +13 -11
- data/lib/as3corelib.rb +10 -4
- data/lib/as3corelib/version.rb +4 -0
- metadata +31 -121
- data/build/build.properties +0 -48
- data/build/build.xml +0 -104
- data/examples/JSONExample/JSONExample.mxml +0 -73
- data/src/com/adobe/air/crypto/EncryptionKeyGenerator.as +0 -313
- data/src/com/adobe/air/filesystem/FileMonitor.as +0 -245
- data/src/com/adobe/air/filesystem/FileUtil.as +0 -63
- data/src/com/adobe/air/filesystem/VolumeMonitor.as +0 -184
- data/src/com/adobe/air/filesystem/events/FileMonitorEvent.as +0 -61
- data/src/com/adobe/air/logging/FileTarget.as +0 -95
- data/src/com/adobe/air/net/ResourceCache.as +0 -165
- data/src/com/adobe/air/net/events/ResourceCacheEvent.as +0 -70
- data/src/com/adobe/crypto/HMAC.as +0 -127
- data/src/com/adobe/crypto/MD5.as +0 -281
- data/src/com/adobe/crypto/MD5Stream.as +0 -402
- data/src/com/adobe/crypto/SHA1.as +0 -289
- data/src/com/adobe/crypto/SHA224.as +0 -257
- data/src/com/adobe/crypto/SHA256.as +0 -261
- data/src/com/adobe/crypto/WSSEUsernameToken.as +0 -114
- data/src/com/adobe/errors/IllegalStateError.as +0 -63
- data/src/com/adobe/fileformats/vcard/Address.as +0 -47
- data/src/com/adobe/fileformats/vcard/Email.as +0 -39
- data/src/com/adobe/fileformats/vcard/Phone.as +0 -39
- data/src/com/adobe/fileformats/vcard/VCard.as +0 -54
- data/src/com/adobe/fileformats/vcard/VCardParser.as +0 -246
- data/src/com/adobe/images/BitString.as +0 -39
- data/src/com/adobe/images/JPGEncoder.as +0 -648
- data/src/com/adobe/images/PNGEncoder.as +0 -141
- data/src/com/adobe/net/DynamicURLLoader.as +0 -55
- data/src/com/adobe/net/IURIResolver.as +0 -76
- data/src/com/adobe/net/MimeTypeMap.as +0 -200
- data/src/com/adobe/net/URI.as +0 -2466
- data/src/com/adobe/net/URIEncodingBitmap.as +0 -139
- data/src/com/adobe/net/proxies/RFC2817Socket.as +0 -198
- data/src/com/adobe/protocols/dict/Database.as +0 -66
- data/src/com/adobe/protocols/dict/Definition.as +0 -71
- data/src/com/adobe/protocols/dict/Dict.as +0 -360
- data/src/com/adobe/protocols/dict/DictionaryServer.as +0 -60
- data/src/com/adobe/protocols/dict/MatchStrategy.as +0 -66
- data/src/com/adobe/protocols/dict/Response.as +0 -71
- data/src/com/adobe/protocols/dict/events/ConnectedEvent.as +0 -53
- data/src/com/adobe/protocols/dict/events/DatabaseEvent.as +0 -67
- data/src/com/adobe/protocols/dict/events/DefinitionEvent.as +0 -70
- data/src/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as +0 -69
- data/src/com/adobe/protocols/dict/events/DictionaryServerEvent.as +0 -69
- data/src/com/adobe/protocols/dict/events/DisconnectedEvent.as +0 -55
- data/src/com/adobe/protocols/dict/events/ErrorEvent.as +0 -80
- data/src/com/adobe/protocols/dict/events/MatchEvent.as +0 -67
- data/src/com/adobe/protocols/dict/events/MatchStrategiesEvent.as +0 -70
- data/src/com/adobe/protocols/dict/events/NoMatchEvent.as +0 -54
- data/src/com/adobe/protocols/dict/util/CompleteResponseEvent.as +0 -68
- data/src/com/adobe/protocols/dict/util/SocketHelper.as +0 -81
- data/src/com/adobe/serialization/json/JSON.as +0 -86
- data/src/com/adobe/serialization/json/JSONDecoder.as +0 -327
- data/src/com/adobe/serialization/json/JSONEncoder.as +0 -312
- data/src/com/adobe/serialization/json/JSONParseError.as +0 -87
- data/src/com/adobe/serialization/json/JSONToken.as +0 -104
- data/src/com/adobe/serialization/json/JSONTokenType.as +0 -69
- data/src/com/adobe/serialization/json/JSONTokenizer.as +0 -702
- data/src/com/adobe/utils/ArrayUtil.as +0 -187
- data/src/com/adobe/utils/DateUtil.as +0 -701
- data/src/com/adobe/utils/DictionaryUtil.as +0 -87
- data/src/com/adobe/utils/IntUtil.as +0 -99
- data/src/com/adobe/utils/NumberFormatter.as +0 -74
- data/src/com/adobe/utils/StringUtil.as +0 -239
- data/src/com/adobe/utils/XMLUtil.as +0 -168
- data/src/com/adobe/webapis/ServiceBase.as +0 -48
- data/src/com/adobe/webapis/URLLoaderBase.as +0 -108
- data/src/com/adobe/webapis/events/ServiceEvent.as +0 -82
- data/tests/src/CoreLibTestRunner-app.xml +0 -135
- data/tests/src/CoreLibTestRunner.as +0 -138
- data/tests/src/CoreLibTestRunner.mxml +0 -46
- data/tests/src/com/adobe/air/crypto/EncryptionKeyGeneratorTest.as +0 -176
- data/tests/src/com/adobe/air/filesystem/FileMonitorTest.as +0 -63
- data/tests/src/com/adobe/air/filesystem/VolumeMonitorTest.as +0 -57
- data/tests/src/com/adobe/air/filesystem/events/FileMonitorEventTest.as +0 -59
- data/tests/src/com/adobe/air/net/events/ResourceCacheEventTest.as +0 -72
- data/tests/src/com/adobe/crypto/HMACMD5Test.as +0 -134
- data/tests/src/com/adobe/crypto/HMACSHA1Test.as +0 -138
- data/tests/src/com/adobe/crypto/MD5Test.as +0 -82
- data/tests/src/com/adobe/crypto/SHA1Test.as +0 -151
- data/tests/src/com/adobe/crypto/SHA224Test.as +0 -104
- data/tests/src/com/adobe/crypto/SHA256Test.as +0 -116
- data/tests/src/com/adobe/crypto/WSSEUsernameTokenTest.as +0 -87
- data/tests/src/com/adobe/images/JPGEncoderTest.as +0 -54
- data/tests/src/com/adobe/images/PNGEncoderTest.as +0 -54
- data/tests/src/com/adobe/net/URITest.as +0 -589
- data/tests/src/com/adobe/protocols/events/ConnectedEventTest.as +0 -59
- data/tests/src/com/adobe/protocols/events/DatabaseEventTest.as +0 -62
- data/tests/src/com/adobe/protocols/events/DefinitionEventTest.as +0 -61
- data/tests/src/com/adobe/protocols/events/DefinitionHeaderEventTest.as +0 -61
- data/tests/src/com/adobe/protocols/events/DictionaryServerEventTest.as +0 -61
- data/tests/src/com/adobe/protocols/events/DisconnectedEventTest.as +0 -59
- data/tests/src/com/adobe/protocols/events/ErrorEventTest.as +0 -63
- data/tests/src/com/adobe/protocols/events/MatchEventTest.as +0 -61
- data/tests/src/com/adobe/protocols/events/MatchStrategiesEventTest.as +0 -61
- data/tests/src/com/adobe/protocols/events/NoMatchEventTest.as +0 -58
- data/tests/src/com/adobe/protocols/util/CompletedResponseEventTest.as +0 -60
- data/tests/src/com/adobe/serialization/json/JSONTest.as +0 -522
- data/tests/src/com/adobe/serialization/json/SimpleClass.as +0 -85
- data/tests/src/com/adobe/utils/ArrayUtilTest.as +0 -173
- data/tests/src/com/adobe/utils/DateUtilTest.as +0 -436
- data/tests/src/com/adobe/utils/DictionaryUtilTest.as +0 -93
- data/tests/src/com/adobe/utils/IntUtilTest.as +0 -73
- data/tests/src/com/adobe/utils/NumberFormatterTest.as +0 -70
- data/tests/src/com/adobe/utils/StringUtilTest.as +0 -304
- data/tests/src/com/adobe/utils/XMLUtilTest.as +0 -101
- data/tests/src/com/adobe/webapis/events/ServiceEventTest.as +0 -66
data/build/build.xml
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0"?>
|
|
2
|
-
<project name="as3corelib" basedir="../" default="lib">
|
|
3
|
-
|
|
4
|
-
<!-- Define variables/paths used in this build script -->
|
|
5
|
-
<property file="./build/build.properties" />
|
|
6
|
-
|
|
7
|
-
<!--
|
|
8
|
-
Have you edit the properties file to make sure the paths are right oo your system?
|
|
9
|
-
-->
|
|
10
|
-
<target name="properties">
|
|
11
|
-
<fail unless="asdoc.exe">The "asdoc.exe" property must be set in ${build.dir}/build.properties.</fail>
|
|
12
|
-
<fail unless="compc.exe">The "compc.exe" property must be set in ${build.dir}/build.properties.</fail>
|
|
13
|
-
<fail unless="mxmlc.exe">The "mxmlc.exe" property must be set in ${build.dir}/build.properties.</fail>
|
|
14
|
-
</target>
|
|
15
|
-
|
|
16
|
-
<!--
|
|
17
|
-
Compile the unit tests for the library, placing the test runner .swf file
|
|
18
|
-
in the bin directory.
|
|
19
|
-
-->
|
|
20
|
-
<target name="compileTests" depends="properties">
|
|
21
|
-
<exec executable="${mxmlc.exe}" dir="${basedir}">
|
|
22
|
-
<!-- Point to the main test runner's application mxml file -->
|
|
23
|
-
<arg line="'${tests.dir}/${testRunner.dir}/${testRunner.name}.mxml'" />
|
|
24
|
-
|
|
25
|
-
<!-- Use AIR configuration file -->
|
|
26
|
-
<arg line="-load-config '${flex2sdk.lib.dir}/../air-config.xml'" />
|
|
27
|
-
|
|
28
|
-
<!-- Place the built .swf file in the "bin" directory -->
|
|
29
|
-
<arg line="-o '${bin.dir}/${testRunner.name}.swf'" />
|
|
30
|
-
|
|
31
|
-
<!-- Define source directories for "src" and "tests" -->
|
|
32
|
-
<arg line="-sp ${src.dir}" />
|
|
33
|
-
<arg line="-sp ${tests.dir}/src" />
|
|
34
|
-
|
|
35
|
-
<!-- Include the necessary framework libraries in the class path -->
|
|
36
|
-
<arg line="-l '${flex2sdk.lib.dir}'" />
|
|
37
|
-
|
|
38
|
-
<!-- Include in the flexunit.swc in the class path -->
|
|
39
|
-
<arg line="-l ${flexunit.swc}" />
|
|
40
|
-
|
|
41
|
-
<!-- Include locale-specific items in the path -->
|
|
42
|
-
<arg line="-locale ${flex2sdk.locale}" />
|
|
43
|
-
<arg line="-l '${flex2sdk.locale.dir}'" />
|
|
44
|
-
</exec>
|
|
45
|
-
</target>
|
|
46
|
-
|
|
47
|
-
<!--
|
|
48
|
-
Runs the unit tests for the library in the stand-alone Flash Player
|
|
49
|
-
-->
|
|
50
|
-
<target name="test" depends="compileTests">
|
|
51
|
-
<!--
|
|
52
|
-
If/When we add support for determinig the status of unit tests
|
|
53
|
-
as part of the ANT build process, we need to change the spawn to
|
|
54
|
-
"no" so that ANT waits until the test runner closes before
|
|
55
|
-
proceeding.
|
|
56
|
-
-->
|
|
57
|
-
<exec executable="${flashDebugPlayer.exe}" spawn="yes">
|
|
58
|
-
<arg line="${bin.dir}/${testRunner.name}.swf" />
|
|
59
|
-
</exec>
|
|
60
|
-
</target>
|
|
61
|
-
|
|
62
|
-
<!--
|
|
63
|
-
Compile all of the classes under the "src" tree into a .swc file
|
|
64
|
-
-->
|
|
65
|
-
<target name="lib" depends="properties">
|
|
66
|
-
<exec executable="${compc.exe}" dir="${basedir}">
|
|
67
|
-
<!-- Specify the name of the output file -->
|
|
68
|
-
<arg line="-o '${bin.dir}/${library.name}.swc'" />
|
|
69
|
-
|
|
70
|
-
<!-- Specify the main source path as "src" -->
|
|
71
|
-
<arg line="-sp ${src.dir}" />
|
|
72
|
-
|
|
73
|
-
<!-- Include all of the classes in the "src" tree -->
|
|
74
|
-
<arg line="-is ${src.dir}" />
|
|
75
|
-
</exec>
|
|
76
|
-
</target>
|
|
77
|
-
|
|
78
|
-
<!--
|
|
79
|
-
Generate ASDoc output for the library
|
|
80
|
-
-->
|
|
81
|
-
<target name="docs" depends="properties">
|
|
82
|
-
<!-- Clean out the contents of the doc directory, without delete "docs" -->
|
|
83
|
-
<!--
|
|
84
|
-
<delete includeemptydirs="true">
|
|
85
|
-
<fileset dir="${docs.dir}" includes="**/*" />
|
|
86
|
-
</delete>
|
|
87
|
-
-->
|
|
88
|
-
|
|
89
|
-
<exec executable="${asdoc.exe}" spawn="no">
|
|
90
|
-
<!-- Place the documentation in the "docs" directory -->
|
|
91
|
-
<arg line="-o ${docs.dir}" />
|
|
92
|
-
|
|
93
|
-
<!-- Specify the main source path as "src" -->
|
|
94
|
-
<arg line="-sp ${src.dir}" />
|
|
95
|
-
|
|
96
|
-
<!-- Document all of the classes in the "src" tree -->
|
|
97
|
-
<arg line="-ds ${src.dir} " />
|
|
98
|
-
|
|
99
|
-
<!-- Include the library name in the window title -->
|
|
100
|
-
<arg line="-window-title 'Adobe ActionScript 3.0 Core Library - ${library.name}' "/>
|
|
101
|
-
</exec>
|
|
102
|
-
</target>
|
|
103
|
-
|
|
104
|
-
</project>
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
|
|
3
|
-
<!--
|
|
4
|
-
Adobe Systems Incorporated(r) Source Code License Agreement
|
|
5
|
-
Copyright(c) 2005 Adobe Systems Incorporated. All rights reserved.
|
|
6
|
-
|
|
7
|
-
Please read this Source Code License Agreement carefully before using
|
|
8
|
-
the source code.
|
|
9
|
-
|
|
10
|
-
Adobe Systems Incorporated grants to you a perpetual, worldwide, non-exclusive,
|
|
11
|
-
no-charge, royalty-free, irrevocable copyright license, to reproduce,
|
|
12
|
-
prepare derivative works of, publicly display, publicly perform, and
|
|
13
|
-
distribute this source code and such derivative works in source or
|
|
14
|
-
object code form without any attribution requirements.
|
|
15
|
-
|
|
16
|
-
The name "Adobe Systems Incorporated" must not be used to endorse or promote products
|
|
17
|
-
derived from the source code without prior written permission.
|
|
18
|
-
|
|
19
|
-
You agree to indemnify, hold harmless and defend Adobe Systems Incorporated from and
|
|
20
|
-
against any loss, damage, claims or lawsuits, including attorney's
|
|
21
|
-
fees that arise or result from your use or distribution of the source
|
|
22
|
-
code.
|
|
23
|
-
|
|
24
|
-
THIS SOURCE CODE IS PROVIDED "AS IS" AND "WITH ALL FAULTS", WITHOUT
|
|
25
|
-
ANY TECHNICAL SUPPORT OR ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
|
|
26
|
-
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
27
|
-
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ALSO, THERE IS NO WARRANTY OF
|
|
28
|
-
NON-INFRINGEMENT, TITLE OR QUIET ENJOYMENT. IN NO EVENT SHALL MACROMEDIA
|
|
29
|
-
OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
30
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
31
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
32
|
-
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
33
|
-
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
34
|
-
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOURCE CODE, EVEN IF
|
|
35
|
-
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
36
|
-
-->
|
|
37
|
-
|
|
38
|
-
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
|
|
39
|
-
layout="absolute"
|
|
40
|
-
creationComplete="service.send()" viewSourceURL="srcview/index.html">
|
|
41
|
-
|
|
42
|
-
<mx:Script>
|
|
43
|
-
<![CDATA[
|
|
44
|
-
import mx.collections.ArrayCollection;
|
|
45
|
-
import mx.rpc.events.ResultEvent;
|
|
46
|
-
import com.adobe.serialization.json.JSON;
|
|
47
|
-
|
|
48
|
-
private function onJSONLoad(event:ResultEvent):void
|
|
49
|
-
{
|
|
50
|
-
var rawData:String = String(event.result);
|
|
51
|
-
var arr:Array = (JSON.decode(rawData) as Array);
|
|
52
|
-
|
|
53
|
-
var dp:ArrayCollection = new ArrayCollection(arr);
|
|
54
|
-
|
|
55
|
-
grid.dataProvider = dp;
|
|
56
|
-
}
|
|
57
|
-
]]>
|
|
58
|
-
</mx:Script>
|
|
59
|
-
|
|
60
|
-
<mx:HTTPService
|
|
61
|
-
id="service"
|
|
62
|
-
resultFormat="text"
|
|
63
|
-
url="http://weblogs.macromedia.com/mesh/mashedpotato.json"
|
|
64
|
-
result="onJSONLoad(event)" />
|
|
65
|
-
|
|
66
|
-
<mx:DataGrid id="grid" right="10" left="10" top="10" bottom="10">
|
|
67
|
-
<mx:columns>
|
|
68
|
-
<mx:DataGridColumn headerText="Service" dataField="src"/>
|
|
69
|
-
<mx:DataGridColumn headerText="Title" dataField="title"/>
|
|
70
|
-
</mx:columns>
|
|
71
|
-
</mx:DataGrid>
|
|
72
|
-
|
|
73
|
-
</mx:Application>
|
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2009, Adobe Systems Incorporated
|
|
3
|
-
All rights reserved.
|
|
4
|
-
|
|
5
|
-
Redistribution and use in source and binary forms, with or without
|
|
6
|
-
modification, are permitted provided that the following conditions are
|
|
7
|
-
met:
|
|
8
|
-
|
|
9
|
-
* Redistributions of source code must retain the above copyright notice,
|
|
10
|
-
this list of conditions and the following disclaimer.
|
|
11
|
-
|
|
12
|
-
* Redistributions in binary form must reproduce the above copyright
|
|
13
|
-
notice, this list of conditions and the following disclaimer in the
|
|
14
|
-
documentation and/or other materials provided with the distribution.
|
|
15
|
-
|
|
16
|
-
* Neither the name of Adobe Systems Incorporated nor the names of its
|
|
17
|
-
contributors may be used to endorse or promote products derived from
|
|
18
|
-
this software without specific prior written permission.
|
|
19
|
-
|
|
20
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
21
|
-
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
22
|
-
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
23
|
-
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
24
|
-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
25
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
26
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
27
|
-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
28
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
29
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
30
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
package com.adobe.air.crypto
|
|
34
|
-
{
|
|
35
|
-
import com.adobe.crypto.SHA256;
|
|
36
|
-
|
|
37
|
-
import flash.data.EncryptedLocalStore;
|
|
38
|
-
import flash.utils.ByteArray;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The EncryptionKeyGenerator class generates an encryption key value, such as you would use
|
|
42
|
-
* to encrypt files or data. For example, the encryption key is suitable to use as
|
|
43
|
-
* an encryption key for an encrypted AIR local SQL (SQLite) database.
|
|
44
|
-
*
|
|
45
|
-
* <p>This class uses techniques and algorithms that are designed for maximum
|
|
46
|
-
* data privacy and security. Use this class to generate an encryption key if your
|
|
47
|
-
* application requires data to be encrypted on a per-user level (in other words,
|
|
48
|
-
* if only one user of the application should be able to access his or her data).
|
|
49
|
-
* In some situations you may also want to use per-user encryption for data even
|
|
50
|
-
* if the application design specifies that other users can access the data. For more
|
|
51
|
-
* information, see
|
|
52
|
-
* "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS34990ABF-C893-47ec-B813-9C9D9587A398.html">Considerations for using encryption with a database</a>"
|
|
53
|
-
* in the guide
|
|
54
|
-
* "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/">Developing Adobe AIR Applications with Flex</a>."</p>
|
|
55
|
-
*
|
|
56
|
-
* <p>The generated encryption key is based on a password that you provide. For any given
|
|
57
|
-
* password, in the same AIR application
|
|
58
|
-
* running in the same user account on the same machine, the encryption key result is
|
|
59
|
-
* the same.</p>
|
|
60
|
-
*
|
|
61
|
-
* <p>To generate an encryption key from a password, use the <code>getEncryptionKey()</code>
|
|
62
|
-
* method. To confirm that a password is a "strong" password before calling the
|
|
63
|
-
* <code>getEncryptionKey()</code> method, use the <code>validateStrongPassword()</code>
|
|
64
|
-
* method.</p>
|
|
65
|
-
*
|
|
66
|
-
* <p>In addition, the EncryptionKeyGenerator includes a utility constant,
|
|
67
|
-
* <code>ENCRYPTED_DB_PASSWORD_ERROR_ID</code>. This constant matches the error ID of
|
|
68
|
-
* the SQLError error that occurs when code that is attempting to open an encrypted database
|
|
69
|
-
* provides the wrong encryption key.</p>
|
|
70
|
-
*
|
|
71
|
-
* <p>This class is designed to create an encryption key suitable for providing the highest
|
|
72
|
-
* level of data privacy and security. In order to achieve that level of security, a few
|
|
73
|
-
* security principles must be followed:</p>
|
|
74
|
-
*
|
|
75
|
-
* <ul>
|
|
76
|
-
* <li>Your application should never store the user-entered password</li>
|
|
77
|
-
* <li>Your application should never store the encryption key returned by the
|
|
78
|
-
* <code>getEncryptionKey()</code> method.</li>
|
|
79
|
-
* <li>Instead, each time the user runs the application and attempts to access the database,
|
|
80
|
-
* your application code should call the <code>getEncryptionKey()</code> method to
|
|
81
|
-
* regenerate the encryption key.</li>
|
|
82
|
-
* </ul>
|
|
83
|
-
*
|
|
84
|
-
* <p>For more information about data security, and an explanation of the security techniques
|
|
85
|
-
* used in the EncryptionKeyGenerator class, see
|
|
86
|
-
* "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS61068DCE-9499-4d40-82B8-B71CC35D832C.html">Example: Generating and using an encryption key</a>"
|
|
87
|
-
* in the guide
|
|
88
|
-
* "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/">Developing Adobe AIR Applications with Flex</a>."</p>
|
|
89
|
-
*/
|
|
90
|
-
public class EncryptionKeyGenerator
|
|
91
|
-
{
|
|
92
|
-
// ------- Constants -------
|
|
93
|
-
/**
|
|
94
|
-
* This constant matches the error ID (3138) of the SQLError error that occurs when
|
|
95
|
-
* code that is attempting to open an encrypted database provides the wrong
|
|
96
|
-
* encryption key.
|
|
97
|
-
*/
|
|
98
|
-
public static const ENCRYPTED_DB_PASSWORD_ERROR_ID:uint = 3138;
|
|
99
|
-
|
|
100
|
-
private static const STRONG_PASSWORD_PATTERN:RegExp = /(?=^.{8,32}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/;
|
|
101
|
-
private static const SALT_ELS_KEY:String = "com.adobe.air.crypto::EncryptedDBSalt$$$";
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
// ------- Constructor -------
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Creates a new EncryptionKeyGenerator instance.
|
|
108
|
-
*/
|
|
109
|
-
public function EncryptionKeyGenerator() {}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
// ------- Public methods -------
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Checks a password and returns a value indicating whether the password is a "strong"
|
|
116
|
-
* password. The criteria for a strong password are:
|
|
117
|
-
*
|
|
118
|
-
* <ul>
|
|
119
|
-
* <li>Minimum 8 characters</li>
|
|
120
|
-
* <li>Maxmium 32 characters</li>
|
|
121
|
-
* <li>Contains at least one lowercase letter</li>
|
|
122
|
-
* <li>Contains at least one uppercase letter</li>
|
|
123
|
-
* <li>Contains at least one number or symbol character</li>
|
|
124
|
-
* </ul>
|
|
125
|
-
*
|
|
126
|
-
* @param password The password to check
|
|
127
|
-
*
|
|
128
|
-
* @return A value indicating whether the password is a strong password (<code>true</code>)
|
|
129
|
-
* or not (<code>false</code>).
|
|
130
|
-
*/
|
|
131
|
-
public function validateStrongPassword(password:String):Boolean
|
|
132
|
-
{
|
|
133
|
-
if (password == null || password.length <= 0)
|
|
134
|
-
{
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return STRONG_PASSWORD_PATTERN.test(password);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Uses a password to generate a 16-byte encryption key. The return value is suitable
|
|
144
|
-
* to use as an encryption key for an encrypted AIR local SQL (SQLite) database.
|
|
145
|
-
*
|
|
146
|
-
* <p>For any given
|
|
147
|
-
* password, calling the <code>getEncryptionKey()</code> method from the same AIR application
|
|
148
|
-
* running in the same user account on the same machine, the encryption key result is
|
|
149
|
-
* the same.
|
|
150
|
-
*
|
|
151
|
-
* <p>This method is designed to create an encryption key suitable for providing the highest
|
|
152
|
-
* level of data privacy and security. In order to achieve that level of security, your
|
|
153
|
-
* application must follow several security principles:</p>
|
|
154
|
-
*
|
|
155
|
-
* <ul>
|
|
156
|
-
* <li>Your application can never store the user-entered password</li>
|
|
157
|
-
* <li>Your application can never store the encryption key returned by the
|
|
158
|
-
* <code>getEncryptionKey()</code> method.</li>
|
|
159
|
-
* <li>Instead, each time the user runs the application and attempts to access the database,
|
|
160
|
-
* call the <code>getEncryptionKey()</code> method to regenerate the encryption key.</li>
|
|
161
|
-
* </ul>
|
|
162
|
-
*
|
|
163
|
-
* <p>For more information about data security, and an explanation of the security techniques
|
|
164
|
-
* used in the EncryptionKeyGenerator class, see
|
|
165
|
-
* "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/WS61068DCE-9499-4d40-82B8-B71CC35D832C.html">Example: Generating and using an encryption key</a>"
|
|
166
|
-
* in the guide
|
|
167
|
-
* "<a href="http://help.adobe.com/en_US/AIR/1.5/devappsflex/">Developing Adobe AIR Applications with Flex</a>."</p>
|
|
168
|
-
*
|
|
169
|
-
* @param password The password to use to generate the encryption key.
|
|
170
|
-
* @param overrideSaltELSKey The EncryptionKeyGenerator creates and stores a random value
|
|
171
|
-
* (known as a <i>salt</i>) as part of the process of
|
|
172
|
-
* generating the encryption key. The first time an application
|
|
173
|
-
* calls the <code>getEncryptionKey()</code> method, the salt
|
|
174
|
-
* value is created and stored in the AIR application's encrypted
|
|
175
|
-
* local store (ELS). From then on, the salt value is loaded from the
|
|
176
|
-
* ELS.
|
|
177
|
-
* <p>If you wish to provide a custom String ELS key for storing
|
|
178
|
-
* the salt value, specify a value for the <code>overrideSaltELSKey</code>
|
|
179
|
-
* parameter. If the parameter is <code>null</code> (the default)
|
|
180
|
-
* a default key name is used.</p>
|
|
181
|
-
*
|
|
182
|
-
* @return The generated encryption key, a 16-byte ByteArray object.
|
|
183
|
-
*
|
|
184
|
-
* @throws ArgumentError If the specified password is not a "strong" password according to the
|
|
185
|
-
* criteria explained in the <code>validateStrongPassword()</code>
|
|
186
|
-
* method description
|
|
187
|
-
*
|
|
188
|
-
* @throws ArgumentError If a non-<code>null</code> value is specified for the <code>overrideSaltELSKey</code>
|
|
189
|
-
* parameter, and the value is an empty String (<code>""</code>)
|
|
190
|
-
*/
|
|
191
|
-
public function getEncryptionKey(password:String, overrideSaltELSKey:String=null):ByteArray
|
|
192
|
-
{
|
|
193
|
-
if (!validateStrongPassword(password))
|
|
194
|
-
{
|
|
195
|
-
throw new ArgumentError("The password must be a strong password. It must be 8-32 characters long. It must contain at least one uppercase letter, at least one lowercase letter, and at least one number or symbol.");
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (overrideSaltELSKey != null && overrideSaltELSKey.length <= 0)
|
|
199
|
-
{
|
|
200
|
-
throw new ArgumentError("If an overrideSaltELSKey parameter value is specified, it can't be an empty String.");
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
var concatenatedPassword:String = concatenatePassword(password);
|
|
204
|
-
|
|
205
|
-
var saltKey:String;
|
|
206
|
-
if (overrideSaltELSKey == null)
|
|
207
|
-
{
|
|
208
|
-
saltKey = SALT_ELS_KEY;
|
|
209
|
-
}
|
|
210
|
-
else
|
|
211
|
-
{
|
|
212
|
-
saltKey = overrideSaltELSKey;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
var salt:ByteArray = EncryptedLocalStore.getItem(saltKey);
|
|
216
|
-
if (salt == null)
|
|
217
|
-
{
|
|
218
|
-
salt = makeSalt();
|
|
219
|
-
EncryptedLocalStore.setItem(saltKey, salt);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
var unhashedKey:ByteArray = xorBytes(concatenatedPassword, salt);
|
|
223
|
-
|
|
224
|
-
var hashedKey:String = SHA256.hashBytes(unhashedKey);
|
|
225
|
-
|
|
226
|
-
var encryptionKey:ByteArray = generateEncryptionKey(hashedKey);
|
|
227
|
-
|
|
228
|
-
return encryptionKey;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
// ------- Creating encryption key -------
|
|
233
|
-
|
|
234
|
-
private function concatenatePassword(pwd:String):String
|
|
235
|
-
{
|
|
236
|
-
var len:int = pwd.length;
|
|
237
|
-
var targetLength:int = 32;
|
|
238
|
-
|
|
239
|
-
if (len == targetLength)
|
|
240
|
-
{
|
|
241
|
-
return pwd;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
var repetitions:int = Math.floor(targetLength / len);
|
|
245
|
-
var excess:int = targetLength % len;
|
|
246
|
-
|
|
247
|
-
var result:String = "";
|
|
248
|
-
|
|
249
|
-
for (var i:uint = 0; i < repetitions; i++)
|
|
250
|
-
{
|
|
251
|
-
result += pwd;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
result += pwd.substr(0, excess);
|
|
255
|
-
|
|
256
|
-
return result;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
private function makeSalt():ByteArray
|
|
261
|
-
{
|
|
262
|
-
var result:ByteArray = new ByteArray;
|
|
263
|
-
|
|
264
|
-
for (var i:uint = 0; i < 8; i++)
|
|
265
|
-
{
|
|
266
|
-
result.writeUnsignedInt(Math.round(Math.random() * uint.MAX_VALUE));
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return result;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
private function xorBytes(passwordString:String, salt:ByteArray):ByteArray
|
|
274
|
-
{
|
|
275
|
-
var result:ByteArray = new ByteArray();
|
|
276
|
-
|
|
277
|
-
for (var i:uint = 0; i < 32; i += 4)
|
|
278
|
-
{
|
|
279
|
-
// Extract 4 bytes from the password string and convert to a uint
|
|
280
|
-
var o1:uint = passwordString.charCodeAt(i) << 24;
|
|
281
|
-
o1 += passwordString.charCodeAt(i + 1) << 16;
|
|
282
|
-
o1 += passwordString.charCodeAt(i + 2) << 8;
|
|
283
|
-
o1 += passwordString.charCodeAt(i + 3);
|
|
284
|
-
|
|
285
|
-
salt.position = i;
|
|
286
|
-
var o2:uint = salt.readUnsignedInt();
|
|
287
|
-
|
|
288
|
-
var xor:uint = o1 ^ o2;
|
|
289
|
-
result.writeUnsignedInt(xor);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
return result;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
private function generateEncryptionKey(hash:String):ByteArray
|
|
297
|
-
{
|
|
298
|
-
var result:ByteArray = new ByteArray();
|
|
299
|
-
|
|
300
|
-
// select a range of 128 bits (32 hex characters) from the hash
|
|
301
|
-
// In this case, we'll use the bits starting from position 17
|
|
302
|
-
for (var i:uint = 0; i < 32; i += 2)
|
|
303
|
-
{
|
|
304
|
-
var position:uint = i + 17;
|
|
305
|
-
var hex:String = hash.substr(position, 2);
|
|
306
|
-
var byte:int = parseInt(hex, 16);
|
|
307
|
-
result.writeByte(byte);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
return result;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|