PageRenderTime 37ms CodeModel.GetById 0ms 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/CFB8Mode.as

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 61 lines | 43 code | 4 blank | 14 comment | 4 complexity | d3c076013767960f54117457de5b6d06 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * CFB8Mode
  3. *
  4. * An ActionScript 3 implementation of the CFB-8 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 com.hurlant.crypto.tests.TestCase;
  12. import flash.utils.ByteArray;
  13. /**
  14. *
  15. * Note: The constructor accepts an optional padding argument, but ignores it otherwise.
  16. */
  17. public class CFB8Mode extends IVMode implements IMode
  18. {
  19. public function CFB8Mode(key:ISymmetricKey, padding:IPad = null) {
  20. super(key, null);
  21. }
  22. public function encrypt(src:ByteArray):void {
  23. var vector:ByteArray = getIV4e();
  24. var tmp:ByteArray = new ByteArray;
  25. for (var i:uint=0;i<src.length;i++) {
  26. tmp.position = 0;
  27. tmp.writeBytes(vector);
  28. key.encrypt(vector);
  29. src[i] ^= vector[0];
  30. // rotate
  31. for (var j:uint=0;j<blockSize-1;j++) {
  32. vector[j] = tmp[j+1];
  33. }
  34. vector[blockSize-1] = src[i];
  35. }
  36. }
  37. public function decrypt(src:ByteArray):void {
  38. var vector:ByteArray = getIV4d();
  39. var tmp:ByteArray = new ByteArray;
  40. for (var i:uint=0;i<src.length;i++) {
  41. var c:uint = src[i];
  42. tmp.position = 0;
  43. tmp.writeBytes(vector); // I <- tmp
  44. key.encrypt(vector); // O <- vector
  45. src[i] ^= vector[0];
  46. // rotate
  47. for (var j:uint=0;j<blockSize-1;j++) {
  48. vector[j] = tmp[j+1];
  49. }
  50. vector[blockSize-1] = c;
  51. }
  52. }
  53. public function toString():String {
  54. return key.toString()+"-cfb8";
  55. }
  56. }
  57. }