PageRenderTime 166ms CodeModel.GetById 80ms app.highlight 16ms RepoModel.GetById 65ms app.codeStats 0ms

/js/lib/Socket.IO-node/support/socket.io-client/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA256Test.as

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 60 lines | 42 code | 5 blank | 13 comment | 2 complexity | 906d2d2353a2f37a5aa44b9e2d60da80 MD5 | raw file
 1/**
 2 * SHA256Test
 3 * 
 4 * A test class for SHA256
 5 * Copyright (c) 2007 Henri Torgemane
 6 * 
 7 * See LICENSE.txt for full license information.
 8 */
 9package com.hurlant.crypto.tests
10{
11	import com.hurlant.crypto.hash.SHA256;
12	import com.hurlant.util.Hex;
13	
14	import flash.utils.ByteArray;
15	
16	public class SHA256Test extends TestCase
17	{
18		public function SHA256Test(h:ITestHarness)
19		{
20			super(h,"SHA-256 Test");
21			runTest(testSha256,"SHA-256 Test Vectors");
22			h.endTestCase();
23		}
24		
25		/**
26		 * Test vectors courtesy of
27		 * https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/sha/Sha-2-256.unverified.test-vectors
28		 */
29		public function testSha256():void {
30			var srcs:Array = [
31			Hex.fromString(""),
32			Hex.fromString("a"),
33			Hex.fromString("abc"),
34			Hex.fromString("message digest"),
35			Hex.fromString("abcdefghijklmnopqrstuvwxyz"),
36			Hex.fromString("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"),
37			Hex.fromString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
38			Hex.fromString("12345678901234567890123456789012345678901234567890123456789012345678901234567890"),
39			];
40			var hashes:Array = [
41			"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
42			"CA978112CA1BBDCAFAC231B39A23DC4DA786EFF8147C4E72B9807785AFEE48BB",
43			"BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD",
44			"F7846F55CF23E14EEBEAB5B4E1550CAD5B509E3348FBC4EFA3A1413D393CB650",
45			"71C480DF93D6AE2F1EFAD1447C66C9525E316218CF51FC8D9ED832F2DAF18B73",
46			"248D6A61D20638B8E5C026930C3E6039A33CE45964FF2167F6ECEDD419DB06C1",
47			"DB4BFCBD4DA0CD85A60C3C37D3FBD8805C77F15FC6B1FDFE614EE0A7C8FDB4C0",
48			"F371BC4A311F2B009EEF952DD83CA80E2B60026C8E935592D0F9C308453C813E"];
49			
50			// loop.
51			var sha256:SHA256 = new SHA256;
52			for (var i:uint=0;i<srcs.length;i++) {
53				var src:ByteArray = Hex.toArray(srcs[i]);
54				var digest:ByteArray = sha256.hash(src);
55				assert("SHA256 Test "+i, Hex.fromArray(digest) == hashes[i].toLowerCase());
56			}
57			
58		}
59	}
60}