pad-iso10126.js 822 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. CryptoJS v3.1.2
  3. code.google.com/p/crypto-js
  4. (c) 2009-2013 by Jeff Mott. All rights reserved.
  5. code.google.com/p/crypto-js/wiki/License
  6. */
  7. /**
  8. * ISO 10126 padding strategy.
  9. */
  10. CryptoJS.pad.Iso10126 = {
  11. pad: function (data, blockSize) {
  12. // Shortcut
  13. var blockSizeBytes = blockSize * 4;
  14. // Count padding bytes
  15. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  16. // Pad
  17. data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
  18. concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
  19. },
  20. unpad: function (data) {
  21. // Get number of padding bytes from last byte
  22. var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
  23. // Remove padding
  24. data.sigBytes -= nPaddingBytes;
  25. }
  26. };