PageRenderTime 440ms CodeModel.GetById 202ms app.highlight 14ms RepoModel.GetById 218ms app.codeStats 0ms

/flash-src/third-party/com/hurlant/crypto/tests/MD5Test.as

http://github.com/gimite/web-socket-js
ActionScript | 58 lines | 41 code | 5 blank | 12 comment | 2 complexity | 1b375085723ec6f38e4f78051c397753 MD5 | raw file
 1/**
 2 * MD5Test
 3 * 
 4 * A test class for MD5
 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.MD5;
12	import com.hurlant.util.Hex;
13	
14	import flash.utils.ByteArray;
15	
16	public class MD5Test extends TestCase
17	{
18		public function MD5Test(h:ITestHarness)
19		{
20			super(h, "MD5 Test");
21			runTest(testMd5,"MD5 Test Vectors");
22			h.endTestCase();
23		}
24		
25		/**
26		 * Test Vectors grabbed from
27		 * http://www.faqs.org/rfcs/rfc1321.html
28		 */
29		public function testMd5():void {
30			var srcs:Array = [
31			"",
32			Hex.fromString("a"),
33			Hex.fromString("abc"),
34			Hex.fromString("message digest"),
35			Hex.fromString("abcdefghijklmnopqrstuvwxyz"),
36			Hex.fromString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"),
37			Hex.fromString("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
38			];
39			var hashes:Array = [
40			"d41d8cd98f00b204e9800998ecf8427e",
41			"0cc175b9c0f1b6a831c399e269772661",
42			"900150983cd24fb0d6963f7d28e17f72",
43			"f96b697d7cb7938d525a2f31aaf161d0",
44			"c3fcd3d76192e4007dfb496cca67e13b",
45			"d174ab98d277d9f5a5611c2c9f419d9f",
46			"57edf4a22be3c955ac49da2e2107b67a"
47			];
48			var md5:MD5 = new MD5;
49			for (var i:uint=0;i<srcs.length;i++) {
50				var src:ByteArray = Hex.toArray(srcs[i]);
51				var digest:ByteArray = md5.hash(src);
52				assert("MD5 Test "+i, Hex.fromArray(digest) == hashes[i]);
53			}
54			
55		}
56		
57	}
58}