PageRenderTime 3ms 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/PKCS5.as

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
ActionScript | 44 lines | 30 code | 5 blank | 9 comment | 4 complexity | 517ed29bc41e2d86e5794320e98d4c99 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. * PKCS5
  3. *
  4. * A padding implementation of PKCS5.
  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 PKCS5 implements IPad
  13. {
  14. private var blockSize:uint;
  15. public function PKCS5(blockSize:uint=0) {
  16. this.blockSize = blockSize;
  17. }
  18. public function pad(a:ByteArray):void {
  19. var c:uint = blockSize-a.length%blockSize;
  20. for (var i:uint=0;i<c;i++){
  21. a[a.length] = c;
  22. }
  23. }
  24. public function unpad(a:ByteArray):void {
  25. var c:uint = a.length%blockSize;
  26. if (c!=0) throw new Error("PKCS#5::unpad: ByteArray.length isn't a multiple of the blockSize");
  27. c = a[a.length-1];
  28. for (var i:uint=c;i>0;i--) {
  29. var v:uint = a[a.length-1];
  30. a.length--;
  31. if (c!=v) throw new Error("PKCS#5:unpad: Invalid padding value. expected ["+c+"], found ["+v+"]");
  32. }
  33. // that is all.
  34. }
  35. public function setBlockSize(bs:uint):void {
  36. blockSize = bs;
  37. }
  38. }
  39. }