UNPKG

1.12 kBJavaScriptView Raw
1;(function (root, factory, undef) {
2 if (typeof exports === "object") {
3 // CommonJS
4 module.exports = exports = factory(require("./core"), require("./cipher-core"));
5 }
6 else if (typeof define === "function" && define.amd) {
7 // AMD
8 define(["./core", "./cipher-core"], factory);
9 }
10 else {
11 // Global (browser)
12 factory(root.CryptoJS);
13 }
14}(this, function (CryptoJS) {
15
16 /**
17 * ISO 10126 padding strategy.
18 */
19 CryptoJS.pad.Iso10126 = {
20 pad: function (data, blockSize) {
21 // Shortcut
22 var blockSizeBytes = blockSize * 4;
23
24 // Count padding bytes
25 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
26
27 // Pad
28 data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)).
29 concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1));
30 },
31
32 unpad: function (data) {
33 // Get number of padding bytes from last byte
34 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff;
35
36 // Remove padding
37 data.sigBytes -= nPaddingBytes;
38 }
39 };
40
41
42 return CryptoJS.pad.Iso10126;
43
44}));
\No newline at end of file