PageRenderTime 222ms CodeModel.GetById 120ms app.highlight 5ms RepoModel.GetById 96ms app.codeStats 0ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 59 lines | 42 code | 4 blank | 13 comment | 1 complexity | caee47c866417b6a0553ed164cb56cb6 MD5 | raw file
 1/**
 2 * TripleDESKeyTest
 3 * 
 4 * A test class for TripleDESKey
 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.symmetric.TripleDESKey;
12	import com.hurlant.util.Hex;
13	import flash.utils.ByteArray;
14	import com.hurlant.crypto.symmetric.ICipher;
15	import com.hurlant.crypto.symmetric.ECBMode;
16	
17	public class TripleDESKeyTest extends TestCase
18	{
19		public function TripleDESKeyTest(h:ITestHarness)
20		{
21			super(h, "Triped Des Test");
22			runTest(testECB,"Triple DES ECB Test Vectors");
23			h.endTestCase();
24		}
25		
26		/**
27		 * Lots of vectors at http://csrc.nist.gov/publications/nistpubs/800-20/800-20.pdf
28		 * XXX move them in here.
29		 */
30		public function testECB():void {
31			var keys:Array = [
32			"010101010101010101010101010101010101010101010101",
33			"dd24b3aafcc69278d650dad234956b01e371384619492ac4",
34			];
35			var pts:Array = [
36			"8000000000000000",
37			"F36B21045A030303",
38			];
39			var cts:Array = [
40			"95F8A5E5DD31D900",
41			"E823A43DEEA4D0A4",
42			];
43			
44			for (var i:uint=0;i<keys.length;i++) {
45				var key:ByteArray = Hex.toArray(keys[i]);
46				var pt:ByteArray = Hex.toArray(pts[i]);
47				var ede:TripleDESKey = new TripleDESKey(key);
48				ede.encrypt(pt);
49				var out:String = Hex.fromArray(pt).toUpperCase();
50				assert("comparing "+cts[i]+" to "+out, cts[i]==out);
51				// now go back to plaintext
52				ede.decrypt(pt);
53				out = Hex.fromArray(pt).toUpperCase();
54				assert("comparing "+pts[i]+" to "+out, pts[i]==out);
55			}
56		}
57		
58	}
59}