PageRenderTime 35ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/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
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  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. */
  9. package 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. public class TripleDESKeyTest extends TestCase
  17. {
  18. public function TripleDESKeyTest(h:ITestHarness)
  19. {
  20. super(h, "Triped Des Test");
  21. runTest(testECB,"Triple DES ECB Test Vectors");
  22. h.endTestCase();
  23. }
  24. /**
  25. * Lots of vectors at http://csrc.nist.gov/publications/nistpubs/800-20/800-20.pdf
  26. * XXX move them in here.
  27. */
  28. public function testECB():void {
  29. var keys:Array = [
  30. "010101010101010101010101010101010101010101010101",
  31. "dd24b3aafcc69278d650dad234956b01e371384619492ac4",
  32. ];
  33. var pts:Array = [
  34. "8000000000000000",
  35. "F36B21045A030303",
  36. ];
  37. var cts:Array = [
  38. "95F8A5E5DD31D900",
  39. "E823A43DEEA4D0A4",
  40. ];
  41. for (var i:uint=0;i<keys.length;i++) {
  42. var key:ByteArray = Hex.toArray(keys[i]);
  43. var pt:ByteArray = Hex.toArray(pts[i]);
  44. var ede:TripleDESKey = new TripleDESKey(key);
  45. ede.encrypt(pt);
  46. var out:String = Hex.fromArray(pt).toUpperCase();
  47. assert("comparing "+cts[i]+" to "+out, cts[i]==out);
  48. // now go back to plaintext
  49. ede.decrypt(pt);
  50. out = Hex.fromArray(pt).toUpperCase();
  51. assert("comparing "+pts[i]+" to "+out, pts[i]==out);
  52. }
  53. }
  54. }
  55. }