PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 60 lines | 44 code | 6 blank | 10 comment | 0 complexity | 67f1216270273a0a5dbcd1df770e6f75 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * SimpleIVMode
  3. *
  4. * A convenience class that automatically places the IV
  5. * at the beginning of the encrypted stream, so it doesn't have to
  6. * be handled explicitely.
  7. * Copyright (c) 2007 Henri Torgemane
  8. *
  9. * See LICENSE.txt for full license information.
  10. */
  11. package com.hurlant.crypto.symmetric
  12. {
  13. import flash.utils.ByteArray;
  14. import com.hurlant.util.Memory;
  15. public class SimpleIVMode implements IMode, ICipher
  16. {
  17. protected var mode:IVMode;
  18. protected var cipher:ICipher;
  19. public function SimpleIVMode(mode:IVMode) {
  20. this.mode = mode;
  21. cipher = mode as ICipher;
  22. }
  23. public function getBlockSize():uint {
  24. return mode.getBlockSize();
  25. }
  26. public function dispose():void {
  27. mode.dispose();
  28. mode = null;
  29. cipher = null;
  30. Memory.gc();
  31. }
  32. public function encrypt(src:ByteArray):void {
  33. cipher.encrypt(src);
  34. var tmp:ByteArray = new ByteArray;
  35. tmp.writeBytes(mode.IV);
  36. tmp.writeBytes(src);
  37. src.position=0;
  38. src.writeBytes(tmp);
  39. }
  40. public function decrypt(src:ByteArray):void {
  41. var tmp:ByteArray = new ByteArray;
  42. tmp.writeBytes(src, 0, getBlockSize());
  43. mode.IV = tmp;
  44. tmp = new ByteArray;
  45. tmp.writeBytes(src, getBlockSize());
  46. cipher.decrypt(tmp);
  47. src.length=0;
  48. src.writeBytes(tmp);
  49. }
  50. public function toString():String {
  51. return "simple-"+cipher.toString();
  52. }
  53. }
  54. }