rocket-js 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. data/.gitignore +0 -11
  2. data/Rakefile +33 -47
  3. data/lib/rocket/js.rb +0 -2
  4. data/lib/rocket/js/builder.rb +2 -2
  5. data/lib/rocket/js/cli.rb +1 -1
  6. data/rocket-js.gemspec +23 -80
  7. data/src/vendor/web-socket-js/FABridge.js +604 -0
  8. data/src/vendor/web-socket-js/README.txt +109 -0
  9. data/src/vendor/web-socket-js/WebSocketMain.swf +0 -0
  10. data/src/vendor/web-socket-js/WebSocketMainInsecure.zip +0 -0
  11. data/src/vendor/web-socket-js/flash-src/WebSocket.as +473 -0
  12. data/src/vendor/web-socket-js/flash-src/WebSocketMain.as +88 -0
  13. data/src/vendor/web-socket-js/flash-src/WebSocketMainInsecure.as +19 -0
  14. data/src/vendor/web-socket-js/flash-src/WebSocketStateEvent.as +32 -0
  15. data/src/vendor/web-socket-js/flash-src/bridge/FABridge.as +943 -0
  16. data/src/vendor/web-socket-js/flash-src/build.sh +10 -0
  17. data/src/vendor/web-socket-js/flash-src/com/adobe/net/proxies/RFC2817Socket.as +204 -0
  18. data/src/vendor/web-socket-js/flash-src/com/gsolo/encryption/MD5.as +375 -0
  19. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/Crypto.as +287 -0
  20. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/MozillaRootCertificates.as +3235 -0
  21. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509Certificate.as +218 -0
  22. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509CertificateCollection.as +57 -0
  23. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/HMAC.as +82 -0
  24. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHMAC.as +27 -0
  25. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHash.as +21 -0
  26. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MAC.as +137 -0
  27. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD2.as +124 -0
  28. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD5.as +204 -0
  29. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA1.as +106 -0
  30. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA224.as +28 -0
  31. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA256.as +115 -0
  32. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHABase.as +71 -0
  33. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/ARC4.as +90 -0
  34. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/IPRNG.as +20 -0
  35. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/Random.as +119 -0
  36. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/TLSPRF.as +142 -0
  37. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/rsa/RSAKey.as +339 -0
  38. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/AESKey.as +2797 -0
  39. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/BlowFishKey.as +375 -0
  40. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CBCMode.as +55 -0
  41. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CFB8Mode.as +61 -0
  42. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CFBMode.as +64 -0
  43. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CTRMode.as +58 -0
  44. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/DESKey.as +365 -0
  45. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ECBMode.as +86 -0
  46. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ICipher.as +21 -0
  47. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IMode.as +15 -0
  48. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IPad.as +32 -0
  49. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IStreamCipher.as +21 -0
  50. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ISymmetricKey.as +35 -0
  51. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IVMode.as +110 -0
  52. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/NullPad.as +34 -0
  53. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/OFBMode.as +52 -0
  54. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/PKCS5.as +44 -0
  55. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SSLPad.as +44 -0
  56. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SimpleIVMode.as +60 -0
  57. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TLSPad.as +42 -0
  58. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TripleDESKey.as +88 -0
  59. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/XTeaKey.as +94 -0
  60. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/aeskey.pl +29 -0
  61. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/dump.txt +2304 -0
  62. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/AESKeyTest.as +1220 -0
  63. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ARC4Test.as +58 -0
  64. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/BigIntegerTest.as +39 -0
  65. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/BlowFishKeyTest.as +148 -0
  66. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CBCModeTest.as +160 -0
  67. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CFB8ModeTest.as +71 -0
  68. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CFBModeTest.as +98 -0
  69. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CTRModeTest.as +109 -0
  70. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/DESKeyTest.as +112 -0
  71. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ECBModeTest.as +151 -0
  72. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/HMACTest.as +184 -0
  73. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ITestHarness.as +20 -0
  74. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/MD2Test.as +56 -0
  75. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/MD5Test.as +58 -0
  76. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/OFBModeTest.as +101 -0
  77. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/RSAKeyTest.as +92 -0
  78. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA1Test.as +198 -0
  79. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA224Test.as +58 -0
  80. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA256Test.as +60 -0
  81. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TLSPRFTest.as +51 -0
  82. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TestCase.as +42 -0
  83. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TripleDESKeyTest.as +59 -0
  84. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/XTeaKeyTest.as +66 -0
  85. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/BulkCiphers.as +102 -0
  86. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/CipherSuites.as +117 -0
  87. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/IConnectionState.as +14 -0
  88. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/ISecurityParameters.as +29 -0
  89. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/KeyExchanges.as +24 -0
  90. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/MACs.as +38 -0
  91. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLConnectionState.as +171 -0
  92. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLEvent.as +26 -0
  93. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLSecurityParameters.as +340 -0
  94. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSConfig.as +70 -0
  95. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSConnectionState.as +151 -0
  96. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSEngine.as +895 -0
  97. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSError.as +39 -0
  98. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSEvent.as +27 -0
  99. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSecurityParameters.as +197 -0
  100. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSocket.as +370 -0
  101. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSocketEvent.as +26 -0
  102. data/src/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSTest.as +180 -0
  103. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/BarrettReduction.as +90 -0
  104. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/BigInteger.as +1543 -0
  105. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/ClassicReduction.as +35 -0
  106. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/IReduction.as +11 -0
  107. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/MontgomeryReduction.as +85 -0
  108. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/NullReduction.as +34 -0
  109. data/src/vendor/web-socket-js/flash-src/com/hurlant/math/bi_internal.as +11 -0
  110. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/ArrayUtil.as +25 -0
  111. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Base64.as +189 -0
  112. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Hex.as +66 -0
  113. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/Memory.as +28 -0
  114. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/ByteString.as +43 -0
  115. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/DER.as +210 -0
  116. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/IAsn1Type.as +21 -0
  117. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Integer.as +44 -0
  118. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/OID.as +35 -0
  119. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/ObjectIdentifier.as +112 -0
  120. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/PEM.as +118 -0
  121. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/PrintableString.as +49 -0
  122. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Sequence.as +90 -0
  123. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Set.as +27 -0
  124. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/Type.as +94 -0
  125. data/src/vendor/web-socket-js/flash-src/com/hurlant/util/der/UTCTime.as +60 -0
  126. data/src/vendor/web-socket-js/sample.html +76 -0
  127. data/src/vendor/web-socket-js/swfobject.js +4 -0
  128. data/src/vendor/web-socket-js/web_socket.js +388 -0
  129. metadata +163 -30
  130. data/lib/rocket/js/version.rb +0 -14
  131. data/rocket-0.0.1.min.js +0 -45
@@ -0,0 +1,86 @@
1
+ /**
2
+ * ECBMode
3
+ *
4
+ * An ActionScript 3 implementation of the ECB confidentiality mode
5
+ * Copyright (c) 2007 Henri Torgemane
6
+ *
7
+ * See LICENSE.txt for full license information.
8
+ */
9
+ package com.hurlant.crypto.symmetric
10
+ {
11
+ import flash.utils.ByteArray;
12
+ import com.hurlant.util.Memory;
13
+ import com.hurlant.util.Hex;
14
+
15
+ /**
16
+ * ECB mode.
17
+ * This uses a padding and a symmetric key.
18
+ * If no padding is given, PKCS#5 is used.
19
+ */
20
+ public class ECBMode implements IMode, ICipher
21
+ {
22
+ private var key:ISymmetricKey;
23
+ private var padding:IPad;
24
+
25
+ public function ECBMode(key:ISymmetricKey, padding:IPad = null) {
26
+ this.key = key;
27
+ if (padding == null) {
28
+ padding = new PKCS5(key.getBlockSize());
29
+ } else {
30
+ padding.setBlockSize(key.getBlockSize());
31
+ }
32
+ this.padding = padding;
33
+ }
34
+
35
+ public function getBlockSize():uint {
36
+ return key.getBlockSize();
37
+ }
38
+
39
+ public function encrypt(src:ByteArray):void {
40
+ padding.pad(src);
41
+ src.position = 0;
42
+ var blockSize:uint = key.getBlockSize();
43
+ var tmp:ByteArray = new ByteArray;
44
+ var dst:ByteArray = new ByteArray;
45
+ for (var i:uint=0;i<src.length;i+=blockSize) {
46
+ tmp.length=0;
47
+ src.readBytes(tmp, 0, blockSize);
48
+ key.encrypt(tmp);
49
+ dst.writeBytes(tmp);
50
+ }
51
+ src.length=0;
52
+ src.writeBytes(dst);
53
+ }
54
+ public function decrypt(src:ByteArray):void {
55
+ src.position = 0;
56
+ var blockSize:uint = key.getBlockSize();
57
+
58
+ // sanity check.
59
+ if (src.length%blockSize!=0) {
60
+ throw new Error("ECB mode cipher length must be a multiple of blocksize "+blockSize);
61
+ }
62
+
63
+ var tmp:ByteArray = new ByteArray;
64
+ var dst:ByteArray = new ByteArray;
65
+ for (var i:uint=0;i<src.length;i+=blockSize) {
66
+ tmp.length=0;
67
+ src.readBytes(tmp, 0, blockSize);
68
+
69
+ key.decrypt(tmp);
70
+ dst.writeBytes(tmp);
71
+ }
72
+ padding.unpad(dst);
73
+ src.length=0;
74
+ src.writeBytes(dst);
75
+ }
76
+ public function dispose():void {
77
+ key.dispose();
78
+ key = null;
79
+ padding = null;
80
+ Memory.gc();
81
+ }
82
+ public function toString():String {
83
+ return key.toString()+"-ecb";
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * ICipher
3
+ *
4
+ * A generic interface to use symmetric ciphers
5
+ * Copyright (c) 2007 Henri Torgemane
6
+ *
7
+ * See LICENSE.txt for full license information.
8
+ */
9
+ package com.hurlant.crypto.symmetric
10
+ {
11
+ import flash.utils.ByteArray;
12
+
13
+ public interface ICipher
14
+ {
15
+ function getBlockSize():uint;
16
+ function encrypt(src:ByteArray):void;
17
+ function decrypt(src:ByteArray):void;
18
+ function dispose():void;
19
+ function toString():String;
20
+ }
21
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * IMode
3
+ *
4
+ * An interface for confidentiality modes to implement
5
+ * This could become deprecated at some point.
6
+ * Copyright (c) 2007 Henri Torgemane
7
+ *
8
+ * See LICENSE.txt for full license information.
9
+ */
10
+ package com.hurlant.crypto.symmetric
11
+ {
12
+ public interface IMode extends ICipher
13
+ {
14
+ }
15
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * IPad
3
+ *
4
+ * An interface for padding mechanisms to implement.
5
+ * Copyright (c) 2007 Henri Torgemane
6
+ *
7
+ * See LICENSE.txt for full license information.
8
+ */
9
+ package com.hurlant.crypto.symmetric
10
+ {
11
+ import flash.utils.ByteArray;
12
+
13
+ /**
14
+ * Tiny interface that represents a padding mechanism.
15
+ */
16
+ public interface IPad
17
+ {
18
+ /**
19
+ * Add padding to the array
20
+ */
21
+ function pad(a:ByteArray):void;
22
+ /**
23
+ * Remove padding from the array.
24
+ * @throws Error if the padding is invalid.
25
+ */
26
+ function unpad(a:ByteArray):void;
27
+ /**
28
+ * Set the blockSize to work on
29
+ */
30
+ function setBlockSize(bs:uint):void;
31
+ }
32
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * IStreamCipher
3
+ *
4
+ * A "marker" interface for stream ciphers.
5
+ * Copyright (c) 2007 Henri Torgemane
6
+ *
7
+ * See LICENSE.txt for full license information.
8
+ */
9
+ package com.hurlant.crypto.symmetric {
10
+
11
+ /**
12
+ * A marker to indicate how this cipher works.
13
+ * A stream cipher:
14
+ * - does not use initialization vector
15
+ * - keeps some internal state between calls to encrypt() and decrypt()
16
+ *
17
+ */
18
+ public interface IStreamCipher extends ICipher {
19
+
20
+ }
21
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * ISymmetricKey
3
+ *
4
+ * An interface for symmetric encryption keys to implement.
5
+ * Copyright (c) 2007 Henri Torgemane
6
+ *
7
+ * See LICENSE.txt for full license information.
8
+ */
9
+ package com.hurlant.crypto.symmetric
10
+ {
11
+ import flash.utils.ByteArray;
12
+
13
+ public interface ISymmetricKey
14
+ {
15
+ /**
16
+ * Returns the block size used by this particular encryption algorithm
17
+ */
18
+ function getBlockSize():uint;
19
+ /**
20
+ * Encrypt one block of data in "block", starting at "index", of length "getBlockSize()"
21
+ */
22
+ function encrypt(block:ByteArray, index:uint=0):void;
23
+ /**
24
+ * Decrypt one block of data in "block", starting at "index", of length "getBlockSize()"
25
+ */
26
+ function decrypt(block:ByteArray, index:uint=0):void;
27
+ /**
28
+ * Attempts to destroy sensitive information from memory, such as encryption keys.
29
+ * Note: This is not guaranteed to work given the Flash sandbox model.
30
+ */
31
+ function dispose():void;
32
+
33
+ function toString():String;
34
+ }
35
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * IVMode
3
+ *
4
+ * An abstract class for confidentialy modes that rely on an initialization vector.
5
+ * Copyright (c) 2007 Henri Torgemane
6
+ *
7
+ * See LICENSE.txt for full license information.
8
+ */
9
+ package com.hurlant.crypto.symmetric
10
+ {
11
+ import com.hurlant.crypto.prng.Random;
12
+ import com.hurlant.crypto.tests.TestCase;
13
+ import com.hurlant.util.Memory;
14
+
15
+ import flash.utils.ByteArray;
16
+
17
+ /**
18
+ * An "abtract" class to avoid redundant code in subclasses
19
+ */
20
+ public class IVMode
21
+ {
22
+ protected var key:ISymmetricKey;
23
+ protected var padding:IPad;
24
+ // random generator used to generate IVs
25
+ protected var prng:Random;
26
+ // optional static IV. used for testing only.
27
+ protected var iv:ByteArray;
28
+ // generated IV is stored here.
29
+ protected var lastIV:ByteArray;
30
+ protected var blockSize:uint;
31
+
32
+
33
+ public function IVMode(key:ISymmetricKey, padding:IPad = null) {
34
+ this.key = key;
35
+ blockSize = key.getBlockSize();
36
+ if (padding == null) {
37
+ padding = new PKCS5(blockSize);
38
+ } else {
39
+ padding.setBlockSize(blockSize);
40
+ }
41
+ this.padding = padding;
42
+
43
+ prng = new Random;
44
+ iv = null;
45
+ lastIV = new ByteArray;
46
+ }
47
+
48
+ public function getBlockSize():uint {
49
+ return key.getBlockSize();
50
+ }
51
+ public function dispose():void {
52
+ var i:uint;
53
+ if (iv != null) {
54
+ for (i=0;i<iv.length;i++) {
55
+ iv[i] = prng.nextByte();
56
+ }
57
+ iv.length=0;
58
+ iv = null;
59
+ }
60
+ if (lastIV != null) {
61
+ for (i=0;i<iv.length;i++) {
62
+ lastIV[i] = prng.nextByte();
63
+ }
64
+ lastIV.length=0;
65
+ lastIV=null;
66
+ }
67
+ key.dispose();
68
+ key = null;
69
+ padding = null;
70
+ prng.dispose();
71
+ prng = null;
72
+ Memory.gc();
73
+ }
74
+ /**
75
+ * Optional function to force the IV value.
76
+ * Normally, an IV gets generated randomly at every encrypt() call.
77
+ * Also, use this to set the IV before calling decrypt()
78
+ * (if not set before decrypt(), the IV is read from the beginning of the stream.)
79
+ */
80
+ public function set IV(value:ByteArray):void {
81
+ iv = value;
82
+ lastIV.length=0;
83
+ lastIV.writeBytes(iv);
84
+ }
85
+ public function get IV():ByteArray {
86
+ return lastIV;
87
+ }
88
+
89
+ protected function getIV4e():ByteArray {
90
+ var vec:ByteArray = new ByteArray;
91
+ if (iv) {
92
+ vec.writeBytes(iv);
93
+ } else {
94
+ prng.nextBytes(vec, blockSize);
95
+ }
96
+ lastIV.length=0;
97
+ lastIV.writeBytes(vec);
98
+ return vec;
99
+ }
100
+ protected function getIV4d():ByteArray {
101
+ var vec:ByteArray = new ByteArray;
102
+ if (iv) {
103
+ vec.writeBytes(iv);
104
+ } else {
105
+ throw new Error("an IV must be set before calling decrypt()");
106
+ }
107
+ return vec;
108
+ }
109
+ }
110
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * NullPad
3
+ *
4
+ * A padding class that doesn't pad.
5
+ * Copyright (c) 2007 Henri Torgemane
6
+ *
7
+ * See LICENSE.txt for full license information.
8
+ */
9
+ package com.hurlant.crypto.symmetric
10
+ {
11
+ import flash.utils.ByteArray;
12
+
13
+ /**
14
+ * A pad that does nothing.
15
+ * Useful when you don't want padding in your Mode.
16
+ */
17
+ public class NullPad implements IPad
18
+ {
19
+ public function unpad(a:ByteArray):void
20
+ {
21
+ return;
22
+ }
23
+
24
+ public function pad(a:ByteArray):void
25
+ {
26
+ return;
27
+ }
28
+
29
+ public function setBlockSize(bs:uint):void {
30
+ return;
31
+ }
32
+
33
+ }
34
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * OFBMode
3
+ *
4
+ * An ActionScript 3 implementation of the OFB confidentiality mode
5
+ * Copyright (c) 2007 Henri Torgemane
6
+ *
7
+ * See LICENSE.txt for full license information.
8
+ */
9
+ package com.hurlant.crypto.symmetric
10
+ {
11
+ import flash.utils.ByteArray;
12
+
13
+ public class OFBMode extends IVMode implements IMode
14
+ {
15
+ public function OFBMode(key:ISymmetricKey, padding:IPad=null)
16
+ {
17
+ super(key, null);
18
+ }
19
+
20
+ public function encrypt(src:ByteArray):void
21
+ {
22
+ var vector:ByteArray = getIV4e();
23
+ core(src, vector);
24
+ }
25
+
26
+ public function decrypt(src:ByteArray):void
27
+ {
28
+ var vector:ByteArray = getIV4d();
29
+ core(src, vector);
30
+ }
31
+
32
+ private function core(src:ByteArray, iv:ByteArray):void {
33
+ var l:uint = src.length;
34
+ var tmp:ByteArray = new ByteArray;
35
+ for (var i:uint=0;i<src.length;i+=blockSize) {
36
+ key.encrypt(iv);
37
+ tmp.position=0;
38
+ tmp.writeBytes(iv);
39
+ var chunk:uint = (i+blockSize<l)?blockSize:l-i;
40
+ for (var j:uint=0;j<chunk;j++) {
41
+ src[i+j] ^= iv[j];
42
+ }
43
+ iv.position=0;
44
+ iv.writeBytes(tmp);
45
+ }
46
+ }
47
+ public function toString():String {
48
+ return key.toString()+"-ofb";
49
+ }
50
+
51
+ }
52
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * PKCS5
3
+ *
4
+ * A padding implementation of PKCS5.
5
+ * Copyright (c) 2007 Henri Torgemane
6
+ *
7
+ * See LICENSE.txt for full license information.
8
+ */
9
+ package com.hurlant.crypto.symmetric
10
+ {
11
+ import flash.utils.ByteArray;
12
+
13
+ public class PKCS5 implements IPad
14
+ {
15
+ private var blockSize:uint;
16
+
17
+ public function PKCS5(blockSize:uint=0) {
18
+ this.blockSize = blockSize;
19
+ }
20
+
21
+ public function pad(a:ByteArray):void {
22
+ var c:uint = blockSize-a.length%blockSize;
23
+ for (var i:uint=0;i<c;i++){
24
+ a[a.length] = c;
25
+ }
26
+ }
27
+ public function unpad(a:ByteArray):void {
28
+ var c:uint = a.length%blockSize;
29
+ if (c!=0) throw new Error("PKCS#5::unpad: ByteArray.length isn't a multiple of the blockSize");
30
+ c = a[a.length-1];
31
+ for (var i:uint=c;i>0;i--) {
32
+ var v:uint = a[a.length-1];
33
+ a.length--;
34
+ if (c!=v) throw new Error("PKCS#5:unpad: Invalid padding value. expected ["+c+"], found ["+v+"]");
35
+ }
36
+ // that is all.
37
+ }
38
+
39
+ public function setBlockSize(bs:uint):void {
40
+ blockSize = bs;
41
+ }
42
+
43
+ }
44
+ }