PageRenderTime 20ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 52 lines | 39 code | 5 blank | 8 comment | 2 complexity | 88a73b5eff4a1f3e960a4bdd3a33a82e MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * OFBMode
  3. *
  4. * An ActionScript 3 implementation of the OFB confidentiality mode
  5. * Copyright (c) 2007 Henri Torgemane
  6. *
  7. * See LICENSE.txt for full license information.
  8. */
  9. package com.hurlant.crypto.symmetric
  10. {
  11. import flash.utils.ByteArray;
  12. public class OFBMode extends IVMode implements IMode
  13. {
  14. public function OFBMode(key:ISymmetricKey, padding:IPad=null)
  15. {
  16. super(key, null);
  17. }
  18. public function encrypt(src:ByteArray):void
  19. {
  20. var vector:ByteArray = getIV4e();
  21. core(src, vector);
  22. }
  23. public function decrypt(src:ByteArray):void
  24. {
  25. var vector:ByteArray = getIV4d();
  26. core(src, vector);
  27. }
  28. private function core(src:ByteArray, iv:ByteArray):void {
  29. var l:uint = src.length;
  30. var tmp:ByteArray = new ByteArray;
  31. for (var i:uint=0;i<src.length;i+=blockSize) {
  32. key.encrypt(iv);
  33. tmp.position=0;
  34. tmp.writeBytes(iv);
  35. var chunk:uint = (i+blockSize<l)?blockSize:l-i;
  36. for (var j:uint=0;j<chunk;j++) {
  37. src[i+j] ^= iv[j];
  38. }
  39. iv.position=0;
  40. iv.writeBytes(tmp);
  41. }
  42. }
  43. public function toString():String {
  44. return key.toString()+"-ofb";
  45. }
  46. }
  47. }