UNPKG

@syncfusion/ej2-pdf

Version:

Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.

155 lines (154 loc) 6.34 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { _AdvancedEncryptionBaseCipher } from './cipher'; /** * Advanced AES-128 encryption cipher helper used internally for PDF encryption. * * @private */ var _AdvancedEncryption128Cipher = /** @class */ (function (_super) { __extends(_AdvancedEncryption128Cipher, _super); function _AdvancedEncryption128Cipher(key) { var _this = _super.call(this) || this; _this._cyclesOfRepetition = 10; _this._keySize = 160; _this._key = new Uint8Array([ 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d ]); _this._key = _this._expandKey(key); return _this; } /** * Expands the provided cipher key into the full AES key schedule. * * @private * @param {Uint8Array} cipherKey - The original cipher key to expand. * @returns {Uint8Array} The expanded key schedule as a `Uint8Array`. */ _AdvancedEncryption128Cipher.prototype._expandKey = function (cipherKey) { var count = 176; var s = this._s; var rcon = this._key; var result = new Uint8Array(count); result.set(cipherKey); for (var j = 16, i = 1; j < count; ++i) { var t1 = result[j - 3]; var t2 = result[j - 2]; var t3 = result[j - 1]; var t4 = result[j - 4]; t1 = s[t1]; t2 = s[t2]; t3 = s[t3]; t4 = s[t4]; t1 ^= rcon[i]; for (var n = 0; n < 4; ++n) { result[j] = t1 ^= result[j - 16]; result[j + 1] = t2 ^= result[j - 15]; result[j + 2] = t3 ^= result[j - 14]; result[j + 3] = t4 ^= result[j - 13]; j += 4; } } return result; }; return _AdvancedEncryption128Cipher; }(_AdvancedEncryptionBaseCipher)); export { _AdvancedEncryption128Cipher }; /** * Advanced AES-256 encryption cipher helper used internally for PDF encryption. * * @private */ var _AdvancedEncryption256Cipher = /** @class */ (function (_super) { __extends(_AdvancedEncryption256Cipher, _super); function _AdvancedEncryption256Cipher(key) { var _this = _super.call(this) || this; _this._cyclesOfRepetition = 14; _this._keySize = 224; _this._key = _this._expandKey(key); return _this; } /** * Expands the provided cipher key into the full AES-256 key schedule. * * @private * @param {Uint16Array} cipherKey - The original cipher key to expand. * @returns {Uint8Array} The expanded key schedule as a `Uint8Array`. */ _AdvancedEncryption256Cipher.prototype._expandKey = function (cipherKey) { var count = 240; var s = this._s; var result = new Uint8Array(count); result.set(cipherKey); var r = 1; var t1; var t2; var t3; var t4; for (var j = 32, i = 1; j < count; ++i) { if (j % 32 === 16) { t1 = s[t1]; t2 = s[t2]; t3 = s[t3]; t4 = s[t4]; } else if (j % 32 === 0) { t1 = result[j - 3]; t2 = result[j - 2]; t3 = result[j - 1]; t4 = result[j - 4]; t1 = s[t1]; t2 = s[t2]; t3 = s[t3]; t4 = s[t4]; t1 ^= r; r = r << 1; if (r >= 256) { r = (r ^ 0x1b) & 0xff; } } for (var n = 0; n < 4; ++n) { result[j] = t1 ^= result[j - 32]; result[j + 1] = t2 ^= result[j - 31]; result[j + 2] = t3 ^= result[j - 30]; result[j + 3] = t4 ^= result[j - 29]; j += 4; } } return result; }; return _AdvancedEncryption256Cipher; }(_AdvancedEncryptionBaseCipher)); export { _AdvancedEncryption256Cipher };