@syncfusion/ej2-pdf 1.0.23 → 23.1.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +260 -0
- package/.gitleaksignore +1 -0
- package/CHANGELOG.md +28 -0
- package/README.md +17 -0
- package/dist/ej2-pdf.umd.min.js +4 -14
- package/dist/ej2-pdf.umd.min.js.map +1 -11
- package/dist/es6/ej2-pdf.es2015.js +48372 -0
- package/dist/es6/ej2-pdf.es2015.js.map +1 -0
- package/dist/es6/ej2-pdf.es5.js +50250 -0
- package/dist/es6/ej2-pdf.es5.js.map +1 -0
- package/dist/global/ej2-pdf.min.js +11 -0
- package/dist/global/ej2-pdf.min.js.map +1 -0
- package/dist/global/index.d.ts +14 -0
- package/index.js +4 -8
- package/license +10 -3
- package/package.json +58 -16
- package/pdf.d.ts +4 -0
- package/pdf.js +4 -0
- package/src/global.js +1 -0
- package/src/index.d.ts +45 -98
- package/src/index.js +45 -96
- package/src/pdf/core/annotations/annotation-collection.d.ts +289 -0
- package/src/pdf/core/annotations/annotation-collection.js +755 -0
- package/src/pdf/core/annotations/annotation.d.ts +5865 -0
- package/src/pdf/core/annotations/annotation.js +14195 -0
- package/src/pdf/core/annotations/index.d.ts +4 -0
- package/src/pdf/core/annotations/index.js +4 -0
- package/src/pdf/core/annotations/pdf-appearance.d.ts +102 -0
- package/src/pdf/core/annotations/pdf-appearance.js +124 -0
- package/src/pdf/core/annotations/pdf-paddings.d.ts +8 -0
- package/src/pdf/core/annotations/pdf-paddings.js +22 -0
- package/src/pdf/core/base-stream.d.ts +86 -0
- package/src/pdf/core/base-stream.js +332 -0
- package/src/pdf/core/content-parser.d.ts +38 -0
- package/src/pdf/core/content-parser.js +359 -0
- package/src/pdf/core/decode-stream.d.ts +21 -0
- package/src/pdf/core/decode-stream.js +120 -0
- package/src/pdf/core/decrypt-stream.d.ts +11 -0
- package/src/pdf/core/decrypt-stream.js +53 -0
- package/src/pdf/core/enumerator.d.ts +1668 -0
- package/src/pdf/core/enumerator.js +1717 -0
- package/src/pdf/core/flate-stream.d.ts +13 -0
- package/src/pdf/core/flate-stream.js +329 -0
- package/src/pdf/core/fonts/index.d.ts +7 -0
- package/{dist/es6/implementation/graphics → src/pdf/core}/fonts/index.js +3 -4
- package/src/pdf/core/fonts/pdf-font-metrics.d.ts +66 -0
- package/src/pdf/core/fonts/pdf-font-metrics.js +192 -0
- package/src/pdf/core/fonts/pdf-standard-font.d.ts +1023 -0
- package/src/pdf/core/fonts/pdf-standard-font.js +1682 -0
- package/src/pdf/core/fonts/pdf-string-format.d.ts +236 -0
- package/src/pdf/core/fonts/pdf-string-format.js +213 -0
- package/src/pdf/core/fonts/string-layouter.d.ts +68 -0
- package/src/pdf/core/fonts/string-layouter.js +437 -0
- package/src/pdf/core/fonts/ttf-reader.d.ts +167 -0
- package/src/pdf/core/fonts/ttf-reader.js +1150 -0
- package/src/pdf/core/fonts/ttf-table.d.ts +132 -0
- package/src/pdf/core/fonts/ttf-table.js +74 -0
- package/src/pdf/core/fonts/unicode-true-type-font.d.ts +50 -0
- package/src/pdf/core/fonts/unicode-true-type-font.js +289 -0
- package/src/pdf/core/form/field.d.ts +3011 -0
- package/src/pdf/core/form/field.js +6828 -0
- package/src/pdf/core/form/form.d.ts +279 -0
- package/src/pdf/core/form/form.js +782 -0
- package/src/pdf/core/form/index.d.ts +2 -0
- package/src/pdf/core/form/index.js +2 -0
- package/src/pdf/core/graphics/images/image-decoder.d.ts +38 -0
- package/src/pdf/core/graphics/images/image-decoder.js +227 -0
- package/src/{implementation → pdf/core}/graphics/images/index.d.ts +0 -5
- package/{dist/es6/implementation → src/pdf/core}/graphics/images/index.js +0 -1
- package/src/pdf/core/graphics/images/pdf-bitmap.d.ts +73 -0
- package/src/pdf/core/graphics/images/pdf-bitmap.js +68 -0
- package/src/pdf/core/graphics/images/pdf-image.d.ts +201 -0
- package/src/pdf/core/graphics/images/pdf-image.js +201 -0
- package/src/pdf/core/graphics/index.d.ts +10 -0
- package/src/pdf/core/graphics/index.js +10 -0
- package/src/pdf/core/graphics/pdf-graphics.d.ts +956 -0
- package/src/pdf/core/graphics/pdf-graphics.js +1860 -0
- package/src/pdf/core/graphics/pdf-path.d.ts +34 -0
- package/src/pdf/core/graphics/pdf-path.js +177 -0
- package/src/pdf/core/graphics/pdf-stream-writer.d.ts +56 -0
- package/src/pdf/core/graphics/pdf-stream-writer.js +231 -0
- package/src/pdf/core/graphics/pdf-template.d.ts +79 -0
- package/src/pdf/core/graphics/pdf-template.js +100 -0
- package/src/pdf/core/graphics/rightToLeft/bidirectional.d.ts +69 -0
- package/src/pdf/core/graphics/rightToLeft/bidirectional.js +831 -0
- package/src/pdf/core/graphics/rightToLeft/index.d.ts +3 -0
- package/src/pdf/core/graphics/rightToLeft/index.js +3 -0
- package/src/pdf/core/graphics/rightToLeft/text-renderer.d.ts +13 -0
- package/src/pdf/core/graphics/rightToLeft/text-renderer.js +116 -0
- package/src/pdf/core/graphics/rightToLeft/text-shape.d.ts +48 -0
- package/src/pdf/core/graphics/rightToLeft/text-shape.js +289 -0
- package/src/pdf/core/import-export/fdf-document.d.ts +37 -0
- package/src/pdf/core/import-export/fdf-document.js +667 -0
- package/src/pdf/core/import-export/index.d.ts +5 -0
- package/src/pdf/core/import-export/index.js +5 -0
- package/src/pdf/core/import-export/json-document.d.ts +47 -0
- package/src/pdf/core/import-export/json-document.js +1547 -0
- package/src/pdf/core/import-export/xfdf-document.d.ts +146 -0
- package/src/pdf/core/import-export/xfdf-document.js +2920 -0
- package/src/pdf/core/import-export/xml-document.d.ts +14 -0
- package/src/pdf/core/import-export/xml-document.js +166 -0
- package/src/pdf/core/import-export/xml-writer.d.ts +69 -0
- package/src/pdf/core/import-export/xml-writer.js +494 -0
- package/src/pdf/core/pdf-catalog.d.ts +18 -0
- package/src/pdf/core/pdf-catalog.js +166 -0
- package/src/pdf/core/pdf-cross-reference.d.ts +80 -0
- package/src/pdf/core/pdf-cross-reference.js +1049 -0
- package/src/pdf/core/pdf-document.d.ts +821 -0
- package/src/pdf/core/pdf-document.js +1022 -0
- package/src/pdf/core/pdf-file-structure.d.ts +54 -0
- package/src/pdf/core/pdf-file-structure.js +65 -0
- package/src/pdf/core/pdf-outline.d.ts +362 -0
- package/src/pdf/core/pdf-outline.js +860 -0
- package/src/pdf/core/pdf-page.d.ts +589 -0
- package/src/pdf/core/pdf-page.js +1049 -0
- package/src/pdf/core/pdf-parser.d.ts +62 -0
- package/src/pdf/core/pdf-parser.js +1035 -0
- package/src/pdf/core/pdf-primitives.d.ts +87 -0
- package/src/pdf/core/pdf-primitives.js +305 -0
- package/src/pdf/core/predictor-stream.d.ts +15 -0
- package/src/pdf/core/predictor-stream.js +214 -0
- package/src/pdf/core/security/encryptor.d.ts +140 -0
- package/src/pdf/core/security/encryptor.js +1616 -0
- package/src/pdf/core/security/index.d.ts +1 -0
- package/src/pdf/core/security/index.js +1 -0
- package/src/pdf/core/utils.d.ts +686 -0
- package/src/pdf/core/utils.js +3625 -0
- package/src/pdf/index.d.ts +44 -0
- package/src/pdf/index.js +44 -0
- package/tslint.json +111 -0
- package/ReadMe.md +0 -13
- package/dist/es6/implementation/actions/action.js +0 -44
- package/dist/es6/implementation/actions/index.js +0 -2
- package/dist/es6/implementation/actions/uri-action.js +0 -38
- package/dist/es6/implementation/annotations/action-link-annotation.js +0 -29
- package/dist/es6/implementation/annotations/annotation-collection.js +0 -93
- package/dist/es6/implementation/annotations/annotation.js +0 -156
- package/dist/es6/implementation/annotations/document-link-annotation.js +0 -48
- package/dist/es6/implementation/annotations/index.js +0 -7
- package/dist/es6/implementation/annotations/link-annotation.js +0 -31
- package/dist/es6/implementation/annotations/pdf-text-web-link.js +0 -178
- package/dist/es6/implementation/annotations/uri-annotation.js +0 -64
- package/dist/es6/implementation/collections/dictionary.js +0 -71
- package/dist/es6/implementation/collections/index.js +0 -3
- package/dist/es6/implementation/collections/object-object-pair/dictionary.js +0 -84
- package/dist/es6/implementation/collections/object-object-pair/index.js +0 -1
- package/dist/es6/implementation/collections/utils.js +0 -8
- package/dist/es6/implementation/document/automatic-fields/automatic-field-info-collection.js +0 -17
- package/dist/es6/implementation/document/automatic-fields/automatic-field-info.js +0 -68
- package/dist/es6/implementation/document/automatic-fields/automatic-field.js +0 -145
- package/dist/es6/implementation/document/automatic-fields/composite-field.js +0 -61
- package/dist/es6/implementation/document/automatic-fields/index.js +0 -7
- package/dist/es6/implementation/document/automatic-fields/multiple-value-field.js +0 -36
- package/dist/es6/implementation/document/automatic-fields/page-count-field.js +0 -53
- package/dist/es6/implementation/document/automatic-fields/pdf-numbers-convertor.js +0 -91
- package/dist/es6/implementation/document/automatic-fields/pdf-page-number-field.js +0 -56
- package/dist/es6/implementation/document/automatic-fields/pdf-template-value-pair.js +0 -34
- package/dist/es6/implementation/document/automatic-fields/single-value-field.js +0 -47
- package/dist/es6/implementation/document/index.js +0 -11
- package/dist/es6/implementation/document/pdf-catalog.js +0 -38
- package/dist/es6/implementation/document/pdf-document-base.js +0 -71
- package/dist/es6/implementation/document/pdf-document-template.js +0 -204
- package/dist/es6/implementation/document/pdf-document.js +0 -175
- package/dist/es6/implementation/drawing/index.js +0 -1
- package/dist/es6/implementation/drawing/pdf-drawing.js +0 -80
- package/dist/es6/implementation/general/enum.js +0 -6
- package/dist/es6/implementation/general/index.js +0 -3
- package/dist/es6/implementation/general/pdf-cache-collection.js +0 -24
- package/dist/es6/implementation/general/pdf-collection.js +0 -26
- package/dist/es6/implementation/general/pdf-destination.js +0 -107
- package/dist/es6/implementation/graphics/brushes/index.js +0 -2
- package/dist/es6/implementation/graphics/brushes/pdf-brush.js +0 -6
- package/dist/es6/implementation/graphics/brushes/pdf-solid-brush.js +0 -53
- package/dist/es6/implementation/graphics/constants.js +0 -11
- package/dist/es6/implementation/graphics/enum.js +0 -100
- package/dist/es6/implementation/graphics/figures/base/element-layouter.js +0 -154
- package/dist/es6/implementation/graphics/figures/base/graphics-element.js +0 -18
- package/dist/es6/implementation/graphics/figures/base/index.js +0 -3
- package/dist/es6/implementation/graphics/figures/base/pdf-shape-element.js +0 -32
- package/dist/es6/implementation/graphics/figures/base/shape-layouter.js +0 -55
- package/dist/es6/implementation/graphics/figures/base/text-layouter.js +0 -123
- package/dist/es6/implementation/graphics/figures/enum.js +0 -11
- package/dist/es6/implementation/graphics/figures/index.js +0 -5
- package/dist/es6/implementation/graphics/figures/layout-element.js +0 -41
- package/dist/es6/implementation/graphics/figures/pdf-template.js +0 -110
- package/dist/es6/implementation/graphics/figures/text-element.js +0 -298
- package/dist/es6/implementation/graphics/fonts/enum.js +0 -45
- package/dist/es6/implementation/graphics/fonts/pdf-font-metrics.js +0 -122
- package/dist/es6/implementation/graphics/fonts/pdf-font.js +0 -159
- package/dist/es6/implementation/graphics/fonts/pdf-standard-font-metrics-factory.js +0 -357
- package/dist/es6/implementation/graphics/fonts/pdf-standard-font.js +0 -124
- package/dist/es6/implementation/graphics/fonts/pdf-string-format.js +0 -239
- package/dist/es6/implementation/graphics/fonts/string-layouter.js +0 -335
- package/dist/es6/implementation/graphics/fonts/string-tokenizer.js +0 -162
- package/dist/es6/implementation/graphics/images/byte-array.js +0 -82
- package/dist/es6/implementation/graphics/images/image-decoder.js +0 -167
- package/dist/es6/implementation/graphics/images/pdf-bitmap.js +0 -41
- package/dist/es6/implementation/graphics/images/pdf-image.js +0 -68
- package/dist/es6/implementation/graphics/index.js +0 -20
- package/dist/es6/implementation/graphics/pdf-color.js +0 -205
- package/dist/es6/implementation/graphics/pdf-graphics.js +0 -1034
- package/dist/es6/implementation/graphics/pdf-margins.js +0 -75
- package/dist/es6/implementation/graphics/pdf-pen.js +0 -180
- package/dist/es6/implementation/graphics/pdf-resources.js +0 -223
- package/dist/es6/implementation/graphics/pdf-transformation-matrix.js +0 -134
- package/dist/es6/implementation/graphics/pdf-transparency.js +0 -22
- package/dist/es6/implementation/graphics/unit-convertor.js +0 -33
- package/dist/es6/implementation/index.js +0 -85
- package/dist/es6/implementation/input-output/cross-table.js +0 -6
- package/dist/es6/implementation/input-output/enum.js +0 -5
- package/dist/es6/implementation/input-output/index.js +0 -8
- package/dist/es6/implementation/input-output/pdf-cross-table.js +0 -346
- package/dist/es6/implementation/input-output/pdf-dictionary-properties.js +0 -60
- package/dist/es6/implementation/input-output/pdf-main-object-collection.js +0 -115
- package/dist/es6/implementation/input-output/pdf-operators.js +0 -75
- package/dist/es6/implementation/input-output/pdf-stream-writer.js +0 -364
- package/dist/es6/implementation/input-output/pdf-writer.js +0 -44
- package/dist/es6/implementation/pages/enum.js +0 -51
- package/dist/es6/implementation/pages/index.js +0 -13
- package/dist/es6/implementation/pages/page-added-event-arguments.js +0 -19
- package/dist/es6/implementation/pages/pdf-document-page-collection.js +0 -120
- package/dist/es6/implementation/pages/pdf-page-base.js +0 -104
- package/dist/es6/implementation/pages/pdf-page-layer-collection.js +0 -115
- package/dist/es6/implementation/pages/pdf-page-layer.js +0 -160
- package/dist/es6/implementation/pages/pdf-page-settings.js +0 -126
- package/dist/es6/implementation/pages/pdf-page-size.js +0 -36
- package/dist/es6/implementation/pages/pdf-page-template-element.js +0 -510
- package/dist/es6/implementation/pages/pdf-page.js +0 -130
- package/dist/es6/implementation/pages/pdf-section-collection.js +0 -95
- package/dist/es6/implementation/pages/pdf-section-page-collection.js +0 -30
- package/dist/es6/implementation/pages/pdf-section-templates.js +0 -71
- package/dist/es6/implementation/pages/pdf-section.js +0 -388
- package/dist/es6/implementation/primitives/index.js +0 -8
- package/dist/es6/implementation/primitives/pdf-array.js +0 -199
- package/dist/es6/implementation/primitives/pdf-boolean.js +0 -66
- package/dist/es6/implementation/primitives/pdf-dictionary.js +0 -220
- package/dist/es6/implementation/primitives/pdf-name.js +0 -102
- package/dist/es6/implementation/primitives/pdf-number.js +0 -94
- package/dist/es6/implementation/primitives/pdf-reference.js +0 -195
- package/dist/es6/implementation/primitives/pdf-stream.js +0 -149
- package/dist/es6/implementation/primitives/pdf-string.js +0 -143
- package/dist/es6/implementation/structured-elements/grid/index.js +0 -1
- package/dist/es6/implementation/structured-elements/grid/pdf-grid-cell.js +0 -512
- package/dist/es6/implementation/structured-elements/grid/pdf-grid-column.js +0 -125
- package/dist/es6/implementation/structured-elements/grid/pdf-grid-row.js +0 -244
- package/dist/es6/implementation/structured-elements/grid/pdf-grid.js +0 -989
- package/dist/es6/implementation/structured-elements/grid/styles/index.js +0 -2
- package/dist/es6/implementation/structured-elements/grid/styles/pdf-borders.js +0 -145
- package/dist/es6/implementation/structured-elements/grid/styles/style.js +0 -267
- package/dist/es6/implementation/structured-elements/index.js +0 -1
- package/dist/es6/implementation/structured-elements/tables/light-tables/enum.js +0 -5
- package/dist/es6/index.js +0 -89
- package/dist/es6/interfaces/i-pdf-cache.js +0 -1
- package/dist/es6/interfaces/i-pdf-changable.js +0 -1
- package/dist/es6/interfaces/i-pdf-primitives.js +0 -1
- package/dist/es6/interfaces/i-pdf-wrapper.js +0 -1
- package/dist/es6/interfaces/i-pdf-writer.js +0 -1
- package/dist/es6/interfaces/index.js +0 -1
- package/dist/global/ej2-pdf-export.js +0 -15979
- package/implementation.d.ts +0 -4
- package/implementation.js +0 -8
- package/interfaces.d.ts +0 -4
- package/interfaces.js +0 -4
- package/src/implementation/actions/action.d.ts +0 -50
- package/src/implementation/actions/action.js +0 -44
- package/src/implementation/actions/index.d.ts +0 -6
- package/src/implementation/actions/index.js +0 -9
- package/src/implementation/actions/uri-action.d.ts +0 -33
- package/src/implementation/actions/uri-action.js +0 -39
- package/src/implementation/annotations/action-link-annotation.d.ts +0 -30
- package/src/implementation/annotations/action-link-annotation.js +0 -32
- package/src/implementation/annotations/annotation-collection.d.ts +0 -77
- package/src/implementation/annotations/annotation-collection.js +0 -91
- package/src/implementation/annotations/annotation.d.ts +0 -152
- package/src/implementation/annotations/annotation.js +0 -146
- package/src/implementation/annotations/document-link-annotation.d.ts +0 -89
- package/src/implementation/annotations/document-link-annotation.js +0 -51
- package/src/implementation/annotations/index.d.ts +0 -11
- package/src/implementation/annotations/index.js +0 -14
- package/src/implementation/annotations/link-annotation.d.ts +0 -23
- package/src/implementation/annotations/link-annotation.js +0 -33
- package/src/implementation/annotations/pdf-text-web-link.d.ts +0 -118
- package/src/implementation/annotations/pdf-text-web-link.js +0 -173
- package/src/implementation/annotations/uri-annotation.d.ts +0 -48
- package/src/implementation/annotations/uri-annotation.js +0 -65
- package/src/implementation/collections/dictionary.d.ts +0 -76
- package/src/implementation/collections/dictionary.js +0 -74
- package/src/implementation/collections/index.d.ts +0 -7
- package/src/implementation/collections/index.js +0 -10
- package/src/implementation/collections/object-object-pair/dictionary.d.ts +0 -62
- package/src/implementation/collections/object-object-pair/dictionary.js +0 -88
- package/src/implementation/collections/object-object-pair/index.d.ts +0 -5
- package/src/implementation/collections/object-object-pair/index.js +0 -8
- package/src/implementation/collections/utils.d.ts +0 -27
- package/src/implementation/collections/utils.js +0 -13
- package/src/implementation/document/automatic-fields/automatic-field-info-collection.d.ts +0 -31
- package/src/implementation/document/automatic-fields/automatic-field-info-collection.js +0 -21
- package/src/implementation/document/automatic-fields/automatic-field-info.d.ts +0 -67
- package/src/implementation/document/automatic-fields/automatic-field-info.js +0 -70
- package/src/implementation/document/automatic-fields/automatic-field.d.ts +0 -41
- package/src/implementation/document/automatic-fields/automatic-field.js +0 -143
- package/src/implementation/document/automatic-fields/composite-field.d.ts +0 -46
- package/src/implementation/document/automatic-fields/composite-field.js +0 -64
- package/src/implementation/document/automatic-fields/index.d.ts +0 -11
- package/src/implementation/document/automatic-fields/index.js +0 -14
- package/src/implementation/document/automatic-fields/multiple-value-field.d.ts +0 -18
- package/src/implementation/document/automatic-fields/multiple-value-field.js +0 -35
- package/src/implementation/document/automatic-fields/page-count-field.d.ts +0 -44
- package/src/implementation/document/automatic-fields/page-count-field.js +0 -53
- package/src/implementation/document/automatic-fields/pdf-numbers-convertor.d.ts +0 -53
- package/src/implementation/document/automatic-fields/pdf-numbers-convertor.js +0 -94
- package/src/implementation/document/automatic-fields/pdf-page-number-field.d.ts +0 -51
- package/src/implementation/document/automatic-fields/pdf-page-number-field.js +0 -56
- package/src/implementation/document/automatic-fields/pdf-template-value-pair.d.ts +0 -38
- package/src/implementation/document/automatic-fields/pdf-template-value-pair.js +0 -38
- package/src/implementation/document/automatic-fields/single-value-field.d.ts +0 -15
- package/src/implementation/document/automatic-fields/single-value-field.js +0 -46
- package/src/implementation/document/index.d.ts +0 -15
- package/src/implementation/document/index.js +0 -18
- package/src/implementation/document/pdf-catalog.d.ts +0 -32
- package/src/implementation/document/pdf-catalog.js +0 -38
- package/src/implementation/document/pdf-document-base.d.ts +0 -117
- package/src/implementation/document/pdf-document-base.js +0 -72
- package/src/implementation/document/pdf-document-template.d.ts +0 -166
- package/src/implementation/document/pdf-document-template.js +0 -207
- package/src/implementation/document/pdf-document.d.ts +0 -206
- package/src/implementation/document/pdf-document.js +0 -166
- package/src/implementation/drawing/index.d.ts +0 -5
- package/src/implementation/drawing/index.js +0 -8
- package/src/implementation/drawing/pdf-drawing.d.ts +0 -93
- package/src/implementation/drawing/pdf-drawing.js +0 -84
- package/src/implementation/general/enum.d.ts +0 -21
- package/src/implementation/general/enum.js +0 -10
- package/src/implementation/general/index.d.ts +0 -7
- package/src/implementation/general/index.js +0 -10
- package/src/implementation/general/pdf-cache-collection.d.ts +0 -33
- package/src/implementation/general/pdf-cache-collection.js +0 -27
- package/src/implementation/general/pdf-collection.d.ts +0 -26
- package/src/implementation/general/pdf-collection.js +0 -30
- package/src/implementation/general/pdf-destination.d.ts +0 -103
- package/src/implementation/general/pdf-destination.js +0 -103
- package/src/implementation/graphics/brushes/index.d.ts +0 -6
- package/src/implementation/graphics/brushes/index.js +0 -9
- package/src/implementation/graphics/brushes/pdf-brush.d.ts +0 -55
- package/src/implementation/graphics/brushes/pdf-brush.js +0 -10
- package/src/implementation/graphics/brushes/pdf-solid-brush.d.ts +0 -77
- package/src/implementation/graphics/brushes/pdf-solid-brush.js +0 -54
- package/src/implementation/graphics/constants.d.ts +0 -31
- package/src/implementation/graphics/constants.js +0 -15
- package/src/implementation/graphics/enum.d.ts +0 -392
- package/src/implementation/graphics/enum.js +0 -104
- package/src/implementation/graphics/figures/base/element-layouter.d.ts +0 -160
- package/src/implementation/graphics/figures/base/element-layouter.js +0 -156
- package/src/implementation/graphics/figures/base/graphics-element.d.ts +0 -16
- package/src/implementation/graphics/figures/base/graphics-element.js +0 -22
- package/src/implementation/graphics/figures/base/index.d.ts +0 -7
- package/src/implementation/graphics/figures/base/index.js +0 -10
- package/src/implementation/graphics/figures/base/pdf-shape-element.d.ts +0 -28
- package/src/implementation/graphics/figures/base/pdf-shape-element.js +0 -34
- package/src/implementation/graphics/figures/base/shape-layouter.d.ts +0 -80
- package/src/implementation/graphics/figures/base/shape-layouter.js +0 -57
- package/src/implementation/graphics/figures/base/text-layouter.d.ts +0 -107
- package/src/implementation/graphics/figures/base/text-layouter.js +0 -121
- package/src/implementation/graphics/figures/enum.d.ts +0 -37
- package/src/implementation/graphics/figures/enum.js +0 -15
- package/src/implementation/graphics/figures/index.d.ts +0 -9
- package/src/implementation/graphics/figures/index.js +0 -12
- package/src/implementation/graphics/figures/layout-element.d.ts +0 -57
- package/src/implementation/graphics/figures/layout-element.js +0 -43
- package/src/implementation/graphics/figures/pdf-template.d.ts +0 -113
- package/src/implementation/graphics/figures/pdf-template.js +0 -106
- package/src/implementation/graphics/figures/text-element.d.ts +0 -213
- package/src/implementation/graphics/figures/text-element.js +0 -289
- package/src/implementation/graphics/fonts/enum.d.ts +0 -179
- package/src/implementation/graphics/fonts/enum.js +0 -49
- package/src/implementation/graphics/fonts/index.d.ts +0 -12
- package/src/implementation/graphics/fonts/index.js +0 -15
- package/src/implementation/graphics/fonts/pdf-font-metrics.d.ts +0 -160
- package/src/implementation/graphics/fonts/pdf-font-metrics.js +0 -123
- package/src/implementation/graphics/fonts/pdf-font.d.ts +0 -187
- package/src/implementation/graphics/fonts/pdf-font.js +0 -158
- package/src/implementation/graphics/fonts/pdf-standard-font-metrics-factory.d.ts +0 -301
- package/src/implementation/graphics/fonts/pdf-standard-font-metrics-factory.js +0 -359
- package/src/implementation/graphics/fonts/pdf-standard-font.d.ts +0 -143
- package/src/implementation/graphics/fonts/pdf-standard-font.js +0 -121
- package/src/implementation/graphics/fonts/pdf-string-format.d.ts +0 -319
- package/src/implementation/graphics/fonts/pdf-string-format.js +0 -241
- package/src/implementation/graphics/fonts/string-layouter.d.ts +0 -255
- package/src/implementation/graphics/fonts/string-layouter.js +0 -336
- package/src/implementation/graphics/fonts/string-tokenizer.d.ts +0 -107
- package/src/implementation/graphics/fonts/string-tokenizer.js +0 -166
- package/src/implementation/graphics/images/byte-array.d.ts +0 -68
- package/src/implementation/graphics/images/byte-array.js +0 -86
- package/src/implementation/graphics/images/image-decoder.d.ts +0 -227
- package/src/implementation/graphics/images/image-decoder.js +0 -164
- package/src/implementation/graphics/images/index.js +0 -11
- package/src/implementation/graphics/images/pdf-bitmap.d.ts +0 -90
- package/src/implementation/graphics/images/pdf-bitmap.js +0 -41
- package/src/implementation/graphics/images/pdf-image.d.ts +0 -88
- package/src/implementation/graphics/images/pdf-image.js +0 -69
- package/src/implementation/graphics/index.d.ts +0 -24
- package/src/implementation/graphics/index.js +0 -27
- package/src/implementation/graphics/pdf-color.d.ts +0 -170
- package/src/implementation/graphics/pdf-color.js +0 -204
- package/src/implementation/graphics/pdf-graphics.d.ts +0 -1085
- package/src/implementation/graphics/pdf-graphics.js +0 -1017
- package/src/implementation/graphics/pdf-margins.d.ts +0 -82
- package/src/implementation/graphics/pdf-margins.js +0 -79
- package/src/implementation/graphics/pdf-pen.d.ts +0 -237
- package/src/implementation/graphics/pdf-pen.js +0 -181
- package/src/implementation/graphics/pdf-resources.d.ts +0 -147
- package/src/implementation/graphics/pdf-resources.js +0 -215
- package/src/implementation/graphics/pdf-transformation-matrix.d.ts +0 -143
- package/src/implementation/graphics/pdf-transformation-matrix.js +0 -136
- package/src/implementation/graphics/pdf-transparency.d.ts +0 -34
- package/src/implementation/graphics/pdf-transparency.js +0 -22
- package/src/implementation/graphics/unit-convertor.d.ts +0 -72
- package/src/implementation/graphics/unit-convertor.js +0 -37
- package/src/implementation/index.d.ts +0 -89
- package/src/implementation/index.js +0 -92
- package/src/implementation/input-output/cross-table.d.ts +0 -21
- package/src/implementation/input-output/cross-table.js +0 -10
- package/src/implementation/input-output/enum.d.ts +0 -16
- package/src/implementation/input-output/enum.js +0 -9
- package/src/implementation/input-output/index.d.ts +0 -12
- package/src/implementation/input-output/index.js +0 -15
- package/src/implementation/input-output/pdf-cross-table.d.ts +0 -249
- package/src/implementation/input-output/pdf-cross-table.js +0 -340
- package/src/implementation/input-output/pdf-dictionary-properties.d.ts +0 -283
- package/src/implementation/input-output/pdf-dictionary-properties.js +0 -64
- package/src/implementation/input-output/pdf-main-object-collection.d.ts +0 -120
- package/src/implementation/input-output/pdf-main-object-collection.js +0 -117
- package/src/implementation/input-output/pdf-operators.d.ts +0 -352
- package/src/implementation/input-output/pdf-operators.js +0 -79
- package/src/implementation/input-output/pdf-stream-writer.d.ts +0 -314
- package/src/implementation/input-output/pdf-stream-writer.js +0 -363
- package/src/implementation/input-output/pdf-writer.d.ts +0 -68
- package/src/implementation/input-output/pdf-writer.js +0 -48
- package/src/implementation/pages/enum.d.ts +0 -201
- package/src/implementation/pages/enum.js +0 -55
- package/src/implementation/pages/index.d.ts +0 -17
- package/src/implementation/pages/index.js +0 -20
- package/src/implementation/pages/page-added-event-arguments.d.ts +0 -30
- package/src/implementation/pages/page-added-event-arguments.js +0 -23
- package/src/implementation/pages/pdf-document-page-collection.d.ts +0 -92
- package/src/implementation/pages/pdf-document-page-collection.js +0 -121
- package/src/implementation/pages/pdf-page-base.d.ts +0 -121
- package/src/implementation/pages/pdf-page-base.js +0 -104
- package/src/implementation/pages/pdf-page-layer-collection.d.ts +0 -99
- package/src/implementation/pages/pdf-page-layer-collection.js +0 -113
- package/src/implementation/pages/pdf-page-layer.d.ts +0 -160
- package/src/implementation/pages/pdf-page-layer.js +0 -159
- package/src/implementation/pages/pdf-page-settings.d.ts +0 -111
- package/src/implementation/pages/pdf-page-settings.js +0 -126
- package/src/implementation/pages/pdf-page-size.d.ts +0 -159
- package/src/implementation/pages/pdf-page-size.js +0 -39
- package/src/implementation/pages/pdf-page-template-element.d.ts +0 -230
- package/src/implementation/pages/pdf-page-template-element.js +0 -509
- package/src/implementation/pages/pdf-page.d.ts +0 -153
- package/src/implementation/pages/pdf-page.js +0 -127
- package/src/implementation/pages/pdf-section-collection.d.ts +0 -109
- package/src/implementation/pages/pdf-section-collection.js +0 -91
- package/src/implementation/pages/pdf-section-page-collection.d.ts +0 -41
- package/src/implementation/pages/pdf-section-page-collection.js +0 -34
- package/src/implementation/pages/pdf-section-templates.d.ts +0 -64
- package/src/implementation/pages/pdf-section-templates.js +0 -74
- package/src/implementation/pages/pdf-section.d.ts +0 -319
- package/src/implementation/pages/pdf-section.js +0 -379
- package/src/implementation/primitives/index.d.ts +0 -12
- package/src/implementation/primitives/index.js +0 -15
- package/src/implementation/primitives/pdf-array.d.ts +0 -186
- package/src/implementation/primitives/pdf-array.js +0 -201
- package/src/implementation/primitives/pdf-boolean.d.ts +0 -84
- package/src/implementation/primitives/pdf-boolean.js +0 -70
- package/src/implementation/primitives/pdf-dictionary.d.ts +0 -311
- package/src/implementation/primitives/pdf-dictionary.js +0 -220
- package/src/implementation/primitives/pdf-name.d.ts +0 -121
- package/src/implementation/primitives/pdf-name.js +0 -106
- package/src/implementation/primitives/pdf-number.d.ts +0 -104
- package/src/implementation/primitives/pdf-number.js +0 -98
- package/src/implementation/primitives/pdf-reference.d.ts +0 -222
- package/src/implementation/primitives/pdf-reference.js +0 -192
- package/src/implementation/primitives/pdf-stream.d.ts +0 -111
- package/src/implementation/primitives/pdf-stream.js +0 -146
- package/src/implementation/primitives/pdf-string.d.ts +0 -212
- package/src/implementation/primitives/pdf-string.js +0 -147
- package/src/implementation/structured-elements/grid/index.d.ts +0 -0
- package/src/implementation/structured-elements/grid/index.js +0 -1
- package/src/implementation/structured-elements/grid/pdf-grid-cell.d.ts +0 -248
- package/src/implementation/structured-elements/grid/pdf-grid-cell.js +0 -504
- package/src/implementation/structured-elements/grid/pdf-grid-column.d.ts +0 -108
- package/src/implementation/structured-elements/grid/pdf-grid-column.js +0 -127
- package/src/implementation/structured-elements/grid/pdf-grid-row.d.ts +0 -207
- package/src/implementation/structured-elements/grid/pdf-grid-row.js +0 -246
- package/src/implementation/structured-elements/grid/pdf-grid.d.ts +0 -678
- package/src/implementation/structured-elements/grid/pdf-grid.js +0 -982
- package/src/implementation/structured-elements/grid/styles/index.d.ts +0 -5
- package/src/implementation/structured-elements/grid/styles/index.js +0 -9
- package/src/implementation/structured-elements/grid/styles/pdf-borders.d.ts +0 -126
- package/src/implementation/structured-elements/grid/styles/pdf-borders.js +0 -146
- package/src/implementation/structured-elements/grid/styles/style.d.ts +0 -250
- package/src/implementation/structured-elements/grid/styles/style.js +0 -269
- package/src/implementation/structured-elements/index.d.ts +0 -0
- package/src/implementation/structured-elements/index.js +0 -1
- package/src/implementation/structured-elements/tables/light-tables/enum.d.ts +0 -16
- package/src/implementation/structured-elements/tables/light-tables/enum.js +0 -9
- package/src/interfaces/i-pdf-cache.d.ts +0 -23
- package/src/interfaces/i-pdf-cache.js +0 -4
- package/src/interfaces/i-pdf-changable.d.ts +0 -17
- package/src/interfaces/i-pdf-changable.js +0 -4
- package/src/interfaces/i-pdf-primitives.d.ts +0 -45
- package/src/interfaces/i-pdf-primitives.js +0 -4
- package/src/interfaces/i-pdf-wrapper.d.ts +0 -13
- package/src/interfaces/i-pdf-wrapper.js +0 -4
- package/src/interfaces/i-pdf-writer.d.ts +0 -29
- package/src/interfaces/i-pdf-writer.js +0 -4
- package/src/interfaces/index.d.ts +0 -9
- package/src/interfaces/index.js +0 -4
|
@@ -0,0 +1,1616 @@
|
|
|
1
|
+
var __extends = (this && this.__extends) || (function () {
|
|
2
|
+
var extendStatics = function (d, b) {
|
|
3
|
+
extendStatics = Object.setPrototypeOf ||
|
|
4
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
6
|
+
return extendStatics(d, b);
|
|
7
|
+
};
|
|
8
|
+
return function (d, b) {
|
|
9
|
+
extendStatics(d, b);
|
|
10
|
+
function __() { this.constructor = d; }
|
|
11
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
12
|
+
};
|
|
13
|
+
})();
|
|
14
|
+
import { _isName, _PdfName } from './../pdf-primitives';
|
|
15
|
+
import { FormatError, _stringToBytes, _areArrayEqual, _bytesToString } from './../utils';
|
|
16
|
+
import { _PdfDecryptStream } from './../decrypt-stream';
|
|
17
|
+
var _PdfEncryptor = /** @class */ (function () {
|
|
18
|
+
function _PdfEncryptor(dictionary, id, password) {
|
|
19
|
+
if (password === void 0) { password = ''; }
|
|
20
|
+
this._isUserPassword = true;
|
|
21
|
+
this._hasUserPasswordOnly = false;
|
|
22
|
+
this._encryptOnlyAttachment = false;
|
|
23
|
+
this._encryptMetaData = true;
|
|
24
|
+
this._defaultPasswordBytes = new Uint8Array([0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff,
|
|
25
|
+
0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a]);
|
|
26
|
+
var filter = dictionary.get('Filter');
|
|
27
|
+
if (!_isName(filter, 'Standard')) {
|
|
28
|
+
throw new FormatError('unknown encryption method');
|
|
29
|
+
}
|
|
30
|
+
this._filterName = filter.name;
|
|
31
|
+
this._dictionary = dictionary;
|
|
32
|
+
var algorithm = dictionary.get('V');
|
|
33
|
+
if (!Number.isInteger(algorithm) || (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 && algorithm !== 5)) {
|
|
34
|
+
throw new FormatError('unsupported encryption algorithm');
|
|
35
|
+
}
|
|
36
|
+
this._algorithm = algorithm;
|
|
37
|
+
var keyLength = dictionary.get('Length');
|
|
38
|
+
if (!keyLength) {
|
|
39
|
+
if (algorithm <= 3) {
|
|
40
|
+
keyLength = 40;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
var cfDictionary = dictionary.get('CF');
|
|
44
|
+
var streamCryptoName = dictionary.get('StmF');
|
|
45
|
+
if (cfDictionary && streamCryptoName) {
|
|
46
|
+
cfDictionary.suppressEncryption = true;
|
|
47
|
+
var handlerDictionary = cfDictionary.get(streamCryptoName.name);
|
|
48
|
+
keyLength = (handlerDictionary && handlerDictionary.get('Length')) || 128;
|
|
49
|
+
if (keyLength < 40) {
|
|
50
|
+
keyLength <<= 3;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!Number.isInteger(keyLength) || keyLength < 40 || keyLength % 8 !== 0) {
|
|
56
|
+
throw new FormatError('invalid key length');
|
|
57
|
+
}
|
|
58
|
+
var ownerPassword = _stringToBytes(dictionary.get('O')).subarray(0, 32);
|
|
59
|
+
var userPassword = _stringToBytes(dictionary.get('U')).subarray(0, 32);
|
|
60
|
+
var flag = dictionary.get('P');
|
|
61
|
+
var revision = dictionary.get('R');
|
|
62
|
+
this._encryptMetaData = (algorithm === 4 || algorithm === 5) && dictionary.get('EncryptMetadata') !== false;
|
|
63
|
+
var fileIdBytes = _stringToBytes(id);
|
|
64
|
+
var passwordBytes;
|
|
65
|
+
if (password) {
|
|
66
|
+
if (revision === 6) {
|
|
67
|
+
password = encodeURIComponent(password);
|
|
68
|
+
}
|
|
69
|
+
passwordBytes = _stringToBytes(password);
|
|
70
|
+
}
|
|
71
|
+
var encryptionKey;
|
|
72
|
+
if (algorithm !== 5) {
|
|
73
|
+
encryptionKey = this._prepareKeyData(fileIdBytes, passwordBytes, ownerPassword, userPassword, flag, revision, keyLength, this._encryptMetaData);
|
|
74
|
+
if (encryptionKey) {
|
|
75
|
+
this._isUserPassword = true;
|
|
76
|
+
if (password) {
|
|
77
|
+
var decodedPassword = this._decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
|
|
78
|
+
var ownerEncryptionKey = this._prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flag, revision, keyLength, this._encryptMetaData);
|
|
79
|
+
if (ownerEncryptionKey && _areArrayEqual(ownerEncryptionKey, encryptionKey)) {
|
|
80
|
+
this._hasUserPasswordOnly = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
var ownerValidationKey = _stringToBytes(dictionary.get('O'));
|
|
87
|
+
var ownerValidationSalt = ownerValidationKey.subarray(32, 40);
|
|
88
|
+
var ownerKeySalt = ownerValidationKey.subarray(40, 48);
|
|
89
|
+
var userValidationKey = _stringToBytes(dictionary.get('U'));
|
|
90
|
+
var uBytes = userValidationKey.subarray(0, 48);
|
|
91
|
+
var userValidationSalt = userValidationKey.subarray(32, 40);
|
|
92
|
+
var userKeySalt = userValidationKey.subarray(40, 48);
|
|
93
|
+
var ownerEncryption = _stringToBytes(dictionary.get('OE'));
|
|
94
|
+
var userEncryption = _stringToBytes(dictionary.get('UE'));
|
|
95
|
+
var algorithm_1;
|
|
96
|
+
if (revision === 6) {
|
|
97
|
+
algorithm_1 = new _AdvancedEncryption();
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
algorithm_1 = new _BasicEncryption();
|
|
101
|
+
}
|
|
102
|
+
var password_1;
|
|
103
|
+
if (passwordBytes) {
|
|
104
|
+
password_1 = passwordBytes.subarray(0, Math.min(127, passwordBytes.length));
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
password_1 = new Uint8Array([]);
|
|
108
|
+
}
|
|
109
|
+
if (algorithm_1._checkUserPassword(password_1, userValidationSalt, userPassword)) {
|
|
110
|
+
encryptionKey = this._createEncryptionKey(true, password_1, ownerKeySalt, uBytes, userKeySalt, ownerEncryption, userEncryption, algorithm_1);
|
|
111
|
+
this._isUserPassword = true;
|
|
112
|
+
if (password_1.length && algorithm_1._checkOwnerPassword(password_1, ownerValidationSalt, uBytes, ownerPassword)) {
|
|
113
|
+
this._hasUserPasswordOnly = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (password_1.length && algorithm_1._checkOwnerPassword(password_1, ownerValidationSalt, uBytes, ownerPassword)) {
|
|
117
|
+
encryptionKey = this._createEncryptionKey(false, passwordBytes, ownerKeySalt, uBytes, userKeySalt, ownerEncryption, userEncryption, algorithm_1);
|
|
118
|
+
this._isUserPassword = false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (!encryptionKey) {
|
|
122
|
+
if (password) {
|
|
123
|
+
var decodedPassword = this._decodeUserPassword(passwordBytes, ownerPassword, revision, keyLength);
|
|
124
|
+
encryptionKey = this._prepareKeyData(fileIdBytes, decodedPassword, ownerPassword, userPassword, flag, revision, keyLength, this._encryptMetaData);
|
|
125
|
+
this._isUserPassword = false;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
throw new Error('Cannot open an encrypted document. The password is invalid.');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
this._encryptionKey = encryptionKey;
|
|
132
|
+
if (algorithm >= 4) {
|
|
133
|
+
var cipherDictionary = dictionary.get('CF');
|
|
134
|
+
if (cipherDictionary) {
|
|
135
|
+
cipherDictionary.suppressEncryption = true;
|
|
136
|
+
if (cipherDictionary.has('StdCF')) {
|
|
137
|
+
var standardCryptFilter = cipherDictionary.get('StdCF');
|
|
138
|
+
if (standardCryptFilter && standardCryptFilter.has('AuthEvent')) {
|
|
139
|
+
var event_1 = standardCryptFilter.get('AuthEvent');
|
|
140
|
+
if (event_1 && event_1.name === 'EFOpen') {
|
|
141
|
+
this._encryptOnlyAttachment = true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
this._cipherDictionary = cipherDictionary;
|
|
147
|
+
this._stream = dictionary.get('StmF') || _PdfName.get('Identity');
|
|
148
|
+
this._string = dictionary.get('StrF') || _PdfName.get('Identity');
|
|
149
|
+
this._eff = dictionary.get('EFF') || this._stream;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
Object.defineProperty(_PdfEncryptor.prototype, "_md5", {
|
|
153
|
+
get: function () {
|
|
154
|
+
if (typeof this._messageDigest === 'undefined') {
|
|
155
|
+
this._messageDigest = new _MD5();
|
|
156
|
+
}
|
|
157
|
+
return this._messageDigest;
|
|
158
|
+
},
|
|
159
|
+
enumerable: true,
|
|
160
|
+
configurable: true
|
|
161
|
+
});
|
|
162
|
+
_PdfEncryptor.prototype._createEncryptionKey = function (isUserKey, password, ownerKeySalt, uBytes, userKeySalt, ownerEncryption, userEncryption, algorithm) {
|
|
163
|
+
if (isUserKey) {
|
|
164
|
+
return algorithm._getUserKey(password, userKeySalt, userEncryption);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
return algorithm._getOwnerKey(password, ownerKeySalt, uBytes, ownerEncryption);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
_PdfEncryptor.prototype._prepareKeyData = function (id, password, ownerPassword, userPassword, flags, revision, keyLength, encryptMetaData) {
|
|
171
|
+
var hashData = new Uint8Array(40 + ownerPassword.length + id.length);
|
|
172
|
+
var i = 0;
|
|
173
|
+
var j = 0;
|
|
174
|
+
var n;
|
|
175
|
+
if (password) {
|
|
176
|
+
n = Math.min(32, password.length);
|
|
177
|
+
for (; i < n; ++i) {
|
|
178
|
+
hashData[Number.parseInt(i.toString(), 10)] = password[Number.parseInt(i.toString(), 10)];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
while (i < 32) {
|
|
182
|
+
hashData[i++] = this._defaultPasswordBytes[j++];
|
|
183
|
+
}
|
|
184
|
+
for (j = 0, n = ownerPassword.length; j < n; ++j) {
|
|
185
|
+
hashData[i++] = ownerPassword[Number.parseInt(j.toString(), 10)];
|
|
186
|
+
}
|
|
187
|
+
hashData[i++] = flags & 0xff;
|
|
188
|
+
hashData[i++] = (flags >> 8) & 0xff;
|
|
189
|
+
hashData[i++] = (flags >> 16) & 0xff;
|
|
190
|
+
hashData[i++] = (flags >>> 24) & 0xff;
|
|
191
|
+
for (j = 0, n = id.length; j < n; ++j) {
|
|
192
|
+
hashData[i++] = id[Number.parseInt(j.toString(), 10)];
|
|
193
|
+
}
|
|
194
|
+
if (revision >= 4 && !encryptMetaData) {
|
|
195
|
+
hashData[i++] = 0xff;
|
|
196
|
+
hashData[i++] = 0xff;
|
|
197
|
+
hashData[i++] = 0xff;
|
|
198
|
+
hashData[i++] = 0xff;
|
|
199
|
+
}
|
|
200
|
+
var hash = this._md5.hash(hashData, 0, i);
|
|
201
|
+
var keyLengthInBytes = keyLength >> 3;
|
|
202
|
+
if (revision >= 3) {
|
|
203
|
+
for (j = 0; j < 50; ++j) {
|
|
204
|
+
hash = this._md5.hash(hash, 0, keyLengthInBytes);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
var encryptionKey = hash.subarray(0, keyLengthInBytes);
|
|
208
|
+
var cipher;
|
|
209
|
+
var checkData;
|
|
210
|
+
if (revision >= 3) {
|
|
211
|
+
for (i = 0; i < 32; ++i) {
|
|
212
|
+
hashData[Number.parseInt(i.toString(), 10)] = this._defaultPasswordBytes[Number.parseInt(i.toString(), 10)];
|
|
213
|
+
}
|
|
214
|
+
for (j = 0, n = id.length; j < n; ++j) {
|
|
215
|
+
hashData[i++] = id[Number.parseInt(j.toString(), 10)];
|
|
216
|
+
}
|
|
217
|
+
cipher = new _NormalCipherFour(encryptionKey);
|
|
218
|
+
checkData = cipher._encryptBlock(this._md5.hash(hashData, 0, i));
|
|
219
|
+
n = encryptionKey.length;
|
|
220
|
+
var derivedKey = new Uint8Array(n);
|
|
221
|
+
for (j = 1; j <= 19; ++j) {
|
|
222
|
+
for (var k = 0; k < n; ++k) {
|
|
223
|
+
derivedKey[Number.parseInt(k.toString(), 10)] = encryptionKey[Number.parseInt(k.toString(), 10)] ^ j;
|
|
224
|
+
}
|
|
225
|
+
cipher = new _NormalCipherFour(derivedKey);
|
|
226
|
+
checkData = cipher._encryptBlock(checkData);
|
|
227
|
+
}
|
|
228
|
+
for (j = 0, n = checkData.length; j < n; ++j) {
|
|
229
|
+
if (userPassword[Number.parseInt(j.toString(), 10)] !== checkData[Number.parseInt(j.toString(), 10)]) {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
cipher = new _NormalCipherFour(encryptionKey);
|
|
236
|
+
checkData = cipher._encryptBlock(this._defaultPasswordBytes);
|
|
237
|
+
for (j = 0, n = checkData.length; j < n; ++j) {
|
|
238
|
+
if (userPassword[Number.parseInt(j.toString(), 10)] !== checkData[Number.parseInt(j.toString(), 10)]) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return encryptionKey;
|
|
244
|
+
};
|
|
245
|
+
_PdfEncryptor.prototype._decodeUserPassword = function (password, ownerPassword, revision, keyLength) {
|
|
246
|
+
var hashData = new Uint8Array(32);
|
|
247
|
+
var i = 0;
|
|
248
|
+
var j = 0;
|
|
249
|
+
var n = Math.min(32, password.length);
|
|
250
|
+
for (; i < n; ++i) {
|
|
251
|
+
hashData[Number.parseInt(i.toString(), 10)] = password[Number.parseInt(i.toString(), 10)];
|
|
252
|
+
}
|
|
253
|
+
while (i < 32) {
|
|
254
|
+
hashData[i++] = this._defaultPasswordBytes[j++];
|
|
255
|
+
}
|
|
256
|
+
var hash = this._md5.hash(hashData, 0, i);
|
|
257
|
+
var keyLengthInBytes = keyLength >> 3;
|
|
258
|
+
if (revision >= 3) {
|
|
259
|
+
for (j = 0; j < 50; ++j) {
|
|
260
|
+
hash = this._md5.hash(hash, 0, hash.length);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
var cipher;
|
|
264
|
+
var userPassword;
|
|
265
|
+
if (revision >= 3) {
|
|
266
|
+
userPassword = ownerPassword;
|
|
267
|
+
var derivedKey = new Uint8Array(keyLengthInBytes);
|
|
268
|
+
for (j = 19; j >= 0; j--) {
|
|
269
|
+
for (var k = 0; k < keyLengthInBytes; ++k) {
|
|
270
|
+
derivedKey[Number.parseInt(k.toString(), 10)] = hash[Number.parseInt(k.toString(), 10)] ^ j;
|
|
271
|
+
}
|
|
272
|
+
cipher = new _NormalCipherFour(derivedKey);
|
|
273
|
+
userPassword = cipher._encryptBlock(userPassword);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
cipher = new _NormalCipherFour(hash.subarray(0, keyLengthInBytes));
|
|
278
|
+
userPassword = cipher._encryptBlock(ownerPassword);
|
|
279
|
+
}
|
|
280
|
+
return userPassword;
|
|
281
|
+
};
|
|
282
|
+
_PdfEncryptor.prototype._createCipherTransform = function (objectNumber, generationNumber) {
|
|
283
|
+
if (this._algorithm === 4 || this._algorithm === 5) {
|
|
284
|
+
var stringCipher = this._buildCipherConstructor(this._cipherDictionary, this._string, objectNumber, generationNumber, this._encryptionKey);
|
|
285
|
+
var streamCipher = this._buildCipherConstructor(this._cipherDictionary, this._stream, objectNumber, generationNumber, this._encryptionKey);
|
|
286
|
+
return new _CipherTransform(stringCipher, streamCipher);
|
|
287
|
+
}
|
|
288
|
+
var key = this._buildObjectKey(objectNumber, generationNumber, this._encryptionKey, false);
|
|
289
|
+
return new _CipherTransform(new _NormalCipherFour(key), new _NormalCipherFour(key));
|
|
290
|
+
};
|
|
291
|
+
_PdfEncryptor.prototype._buildCipherConstructor = function (cipherDictionary, name, objectNumber, generationNumber, key) {
|
|
292
|
+
var cryptFilter = cipherDictionary.get(name.name);
|
|
293
|
+
var cfm;
|
|
294
|
+
if (cryptFilter) {
|
|
295
|
+
cfm = cryptFilter.get('CFM');
|
|
296
|
+
}
|
|
297
|
+
if (!cfm) {
|
|
298
|
+
return new _NullCipher();
|
|
299
|
+
}
|
|
300
|
+
switch (cfm.name) {
|
|
301
|
+
case 'None':
|
|
302
|
+
return new _NullCipher();
|
|
303
|
+
case 'AESV2':
|
|
304
|
+
return new _AdvancedEncryption128Cipher(this._buildObjectKey(objectNumber, generationNumber, key, true));
|
|
305
|
+
case 'AESV3':
|
|
306
|
+
return new _AdvancedEncryption256Cipher(key);
|
|
307
|
+
case 'V2':
|
|
308
|
+
return new _NormalCipherFour(this._buildObjectKey(objectNumber, generationNumber, key, false));
|
|
309
|
+
}
|
|
310
|
+
throw new FormatError('Unknown cryptography method');
|
|
311
|
+
};
|
|
312
|
+
_PdfEncryptor.prototype._buildObjectKey = function (objectNumber, generationNumber, encryptionKey, isAdvancedEncryption) {
|
|
313
|
+
if (isAdvancedEncryption === void 0) { isAdvancedEncryption = false; }
|
|
314
|
+
var key = new Uint8Array(encryptionKey.length + 9);
|
|
315
|
+
var i;
|
|
316
|
+
for (i = 0; i < encryptionKey.length; ++i) {
|
|
317
|
+
key[Number.parseInt(i.toString(), 10)] = encryptionKey[Number.parseInt(i.toString(), 10)];
|
|
318
|
+
}
|
|
319
|
+
key[i++] = objectNumber & 0xff;
|
|
320
|
+
key[i++] = (objectNumber >> 8) & 0xff;
|
|
321
|
+
key[i++] = (objectNumber >> 16) & 0xff;
|
|
322
|
+
key[i++] = generationNumber & 0xff;
|
|
323
|
+
key[i++] = (generationNumber >> 8) & 0xff;
|
|
324
|
+
if (isAdvancedEncryption) {
|
|
325
|
+
key[i++] = 0x73;
|
|
326
|
+
key[i++] = 0x41;
|
|
327
|
+
key[i++] = 0x6c;
|
|
328
|
+
key[i++] = 0x54;
|
|
329
|
+
}
|
|
330
|
+
var hash = this._md5.hash(key, 0, i);
|
|
331
|
+
return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
|
|
332
|
+
};
|
|
333
|
+
return _PdfEncryptor;
|
|
334
|
+
}());
|
|
335
|
+
export { _PdfEncryptor };
|
|
336
|
+
var _MD5 = /** @class */ (function () {
|
|
337
|
+
function _MD5() {
|
|
338
|
+
this._r = new Uint8Array([7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 5, 9, 14, 20, 5, 9,
|
|
339
|
+
14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 6, 10, 15, 21,
|
|
340
|
+
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
|
|
341
|
+
this._k = new Int32Array([-680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426, -1473231341, -45705983,
|
|
342
|
+
1770035416, -1958414417, -42063, -1990404162, 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
|
|
343
|
+
643717713, -373897302, -701558691, 38016083, -660478335, -405537848, 568446438, -1019803690, -187363961, 1163531501,
|
|
344
|
+
-1444681467, -51403784, 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556, -1530992060, 1272893353,
|
|
345
|
+
-155497632, -1094730640, 681279174, -358537222, -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
|
|
346
|
+
-198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606, -1051523, -2054922799, 1873313359, -30611744,
|
|
347
|
+
-1560198380, 1309151649, -145523070, -1120210379, 718787259, -343485551]);
|
|
348
|
+
}
|
|
349
|
+
_MD5.prototype.hash = function (data, offset, length) {
|
|
350
|
+
var h0 = 1732584193;
|
|
351
|
+
var h1 = -271733879;
|
|
352
|
+
var h2 = -1732584194;
|
|
353
|
+
var h3 = 271733878;
|
|
354
|
+
var paddedLength = (length + 72) & ~63;
|
|
355
|
+
var padded = new Uint8Array(paddedLength);
|
|
356
|
+
var i = 0;
|
|
357
|
+
var j = 0;
|
|
358
|
+
for (; i < length; ++i) {
|
|
359
|
+
padded[Number.parseInt(i.toString(), 10)] = data[offset++];
|
|
360
|
+
}
|
|
361
|
+
padded[i++] = 0x80;
|
|
362
|
+
var n = paddedLength - 8;
|
|
363
|
+
while (i < n) {
|
|
364
|
+
padded[i++] = 0;
|
|
365
|
+
}
|
|
366
|
+
padded[i++] = (length << 3) & 0xff;
|
|
367
|
+
padded[i++] = (length >> 5) & 0xff;
|
|
368
|
+
padded[i++] = (length >> 13) & 0xff;
|
|
369
|
+
padded[i++] = (length >> 21) & 0xff;
|
|
370
|
+
padded[i++] = (length >>> 29) & 0xff;
|
|
371
|
+
padded[i++] = 0;
|
|
372
|
+
padded[i++] = 0;
|
|
373
|
+
padded[i++] = 0;
|
|
374
|
+
var w = new Int32Array(16);
|
|
375
|
+
for (i = 0; i < paddedLength;) {
|
|
376
|
+
for (j = 0; j < 16; ++j, i += 4) {
|
|
377
|
+
w[Number.parseInt(j.toString(), 10)] = padded[Number.parseInt(i.toString(), 10)] |
|
|
378
|
+
(padded[i + 1] << 8) |
|
|
379
|
+
(padded[i + 2] << 16) |
|
|
380
|
+
(padded[i + 3] << 24);
|
|
381
|
+
}
|
|
382
|
+
var a = h0;
|
|
383
|
+
var b = h1;
|
|
384
|
+
var c = h2;
|
|
385
|
+
var d = h3;
|
|
386
|
+
var e = void 0;
|
|
387
|
+
var f = void 0;
|
|
388
|
+
for (j = 0; j < 64; ++j) {
|
|
389
|
+
if (j < 16) {
|
|
390
|
+
e = (b & c) | (~b & d);
|
|
391
|
+
f = j;
|
|
392
|
+
}
|
|
393
|
+
else if (j < 32) {
|
|
394
|
+
e = (d & b) | (~d & c);
|
|
395
|
+
f = (5 * j + 1) & 15;
|
|
396
|
+
}
|
|
397
|
+
else if (j < 48) {
|
|
398
|
+
e = b ^ c ^ d;
|
|
399
|
+
f = (3 * j + 5) & 15;
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
e = c ^ (b | ~d);
|
|
403
|
+
f = (7 * j) & 15;
|
|
404
|
+
}
|
|
405
|
+
var previous = d;
|
|
406
|
+
var current = (a + e + this._k[Number.parseInt(j.toString(), 10)] + w[Number.parseInt(f.toString(), 10)]) | 0;
|
|
407
|
+
var rotate = this._r[Number.parseInt(j.toString(), 10)];
|
|
408
|
+
d = c;
|
|
409
|
+
c = b;
|
|
410
|
+
b = (b + ((current << rotate) | (current >>> (32 - rotate)))) | 0;
|
|
411
|
+
a = previous;
|
|
412
|
+
}
|
|
413
|
+
h0 = (h0 + a) | 0;
|
|
414
|
+
h1 = (h1 + b) | 0;
|
|
415
|
+
h2 = (h2 + c) | 0;
|
|
416
|
+
h3 = (h3 + d) | 0;
|
|
417
|
+
}
|
|
418
|
+
return new Uint8Array([h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF, h1 & 0xFF,
|
|
419
|
+
(h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF, h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF,
|
|
420
|
+
(h2 >>> 24) & 0xFF, h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
|
|
421
|
+
]);
|
|
422
|
+
};
|
|
423
|
+
return _MD5;
|
|
424
|
+
}());
|
|
425
|
+
export { _MD5 };
|
|
426
|
+
var _Sha256 = /** @class */ (function () {
|
|
427
|
+
function _Sha256() {
|
|
428
|
+
}
|
|
429
|
+
_Sha256.prototype._rotateRight = function (x, n) {
|
|
430
|
+
return (x >>> n) | (x << (32 - n));
|
|
431
|
+
};
|
|
432
|
+
_Sha256.prototype._sigma = function (x) {
|
|
433
|
+
return this._rotateRight(x, 2) ^ this._rotateRight(x, 13) ^ this._rotateRight(x, 22);
|
|
434
|
+
};
|
|
435
|
+
_Sha256.prototype._sigmaPrime = function (x) {
|
|
436
|
+
return this._rotateRight(x, 6) ^ this._rotateRight(x, 11) ^ this._rotateRight(x, 25);
|
|
437
|
+
};
|
|
438
|
+
_Sha256.prototype._littleSigma = function (x) {
|
|
439
|
+
return this._rotateRight(x, 7) ^ this._rotateRight(x, 18) ^ (x >>> 3);
|
|
440
|
+
};
|
|
441
|
+
_Sha256.prototype._littleSigmaPrime = function (x) {
|
|
442
|
+
return this._rotateRight(x, 17) ^ this._rotateRight(x, 19) ^ (x >>> 10);
|
|
443
|
+
};
|
|
444
|
+
_Sha256.prototype._hash = function (data, offset, length) {
|
|
445
|
+
var h0 = 0x6a09e667;
|
|
446
|
+
var h1 = 0xbb67ae85;
|
|
447
|
+
var h2 = 0x3c6ef372;
|
|
448
|
+
var h3 = 0xa54ff53a;
|
|
449
|
+
var h4 = 0x510e527f;
|
|
450
|
+
var h5 = 0x9b05688c;
|
|
451
|
+
var h6 = 0x1f83d9ab;
|
|
452
|
+
var h7 = 0x5be0cd19;
|
|
453
|
+
var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98,
|
|
454
|
+
0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6,
|
|
455
|
+
0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3,
|
|
456
|
+
0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e,
|
|
457
|
+
0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116,
|
|
458
|
+
0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814,
|
|
459
|
+
0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
|
|
460
|
+
var paddedLength = Math.ceil((length + 9) / 64) * 64;
|
|
461
|
+
var padded = new Uint8Array(paddedLength);
|
|
462
|
+
var i = 0;
|
|
463
|
+
var j;
|
|
464
|
+
for (; i < length; ++i) {
|
|
465
|
+
padded[Number.parseInt(i.toString(), 10)] = data[offset++];
|
|
466
|
+
}
|
|
467
|
+
padded[i++] = 0x80;
|
|
468
|
+
var n = paddedLength - 8;
|
|
469
|
+
while (i < n) {
|
|
470
|
+
padded[i++] = 0;
|
|
471
|
+
}
|
|
472
|
+
padded[i++] = 0;
|
|
473
|
+
padded[i++] = 0;
|
|
474
|
+
padded[i++] = 0;
|
|
475
|
+
padded[i++] = (length >>> 29) & 0xff;
|
|
476
|
+
padded[i++] = (length >> 21) & 0xff;
|
|
477
|
+
padded[i++] = (length >> 13) & 0xff;
|
|
478
|
+
padded[i++] = (length >> 5) & 0xff;
|
|
479
|
+
padded[i++] = (length << 3) & 0xff;
|
|
480
|
+
var w = new Uint32Array(64);
|
|
481
|
+
for (i = 0; i < paddedLength;) {
|
|
482
|
+
for (j = 0; j < 16; ++j) {
|
|
483
|
+
w[Number.parseInt(j.toString(), 10)] = (padded[Number.parseInt(i.toString(), 10)] << 24) |
|
|
484
|
+
(padded[i + 1] << 16) |
|
|
485
|
+
(padded[i + 2] << 8) |
|
|
486
|
+
padded[i + 3];
|
|
487
|
+
i += 4;
|
|
488
|
+
}
|
|
489
|
+
for (j = 16; j < 64; ++j) {
|
|
490
|
+
w[Number.parseInt(j.toString(), 10)] = (this._littleSigmaPrime(w[j - 2]) +
|
|
491
|
+
w[j - 7] +
|
|
492
|
+
this._littleSigma(w[j - 15]) + w[j - 16]) | 0;
|
|
493
|
+
}
|
|
494
|
+
var a = h0;
|
|
495
|
+
var b = h1;
|
|
496
|
+
var c = h2;
|
|
497
|
+
var d = h3;
|
|
498
|
+
var e = h4;
|
|
499
|
+
var f = h5;
|
|
500
|
+
var g = h6;
|
|
501
|
+
var h = h7;
|
|
502
|
+
var t1 = void 0;
|
|
503
|
+
var t2 = void 0;
|
|
504
|
+
for (j = 0; j < 64; ++j) {
|
|
505
|
+
t1 = h +
|
|
506
|
+
this._sigmaPrime(e) +
|
|
507
|
+
((e & f) ^ (~e & g)) +
|
|
508
|
+
k[Number.parseInt(j.toString(), 10)] +
|
|
509
|
+
w[Number.parseInt(j.toString(), 10)];
|
|
510
|
+
t2 = this._sigma(a) + ((a & b) ^ (a & c) ^ (b & c));
|
|
511
|
+
h = g;
|
|
512
|
+
g = f;
|
|
513
|
+
f = e;
|
|
514
|
+
e = (d + t1) | 0;
|
|
515
|
+
d = c;
|
|
516
|
+
c = b;
|
|
517
|
+
b = a;
|
|
518
|
+
a = (t1 + t2) | 0;
|
|
519
|
+
}
|
|
520
|
+
h0 = (h0 + a) | 0;
|
|
521
|
+
h1 = (h1 + b) | 0;
|
|
522
|
+
h2 = (h2 + c) | 0;
|
|
523
|
+
h3 = (h3 + d) | 0;
|
|
524
|
+
h4 = (h4 + e) | 0;
|
|
525
|
+
h5 = (h5 + f) | 0;
|
|
526
|
+
h6 = (h6 + g) | 0;
|
|
527
|
+
h7 = (h7 + h) | 0;
|
|
528
|
+
}
|
|
529
|
+
return new Uint8Array([(h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF, (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF,
|
|
530
|
+
(h1 >> 8) & 0xFF, (h1) & 0xFF, (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF, (h3 >> 24) & 0xFF,
|
|
531
|
+
(h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF, (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
|
|
532
|
+
(h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF, (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF,
|
|
533
|
+
(h6) & 0xFF, (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
|
|
534
|
+
]);
|
|
535
|
+
};
|
|
536
|
+
return _Sha256;
|
|
537
|
+
}());
|
|
538
|
+
export { _Sha256 };
|
|
539
|
+
var _Sha512 = /** @class */ (function () {
|
|
540
|
+
function _Sha512() {
|
|
541
|
+
this._k = [new _Word64(0x428a2f98, 0xd728ae22), new _Word64(0x71374491, 0x23ef65cd),
|
|
542
|
+
new _Word64(0xb5c0fbcf, 0xec4d3b2f), new _Word64(0xe9b5dba5, 0x8189dbbc),
|
|
543
|
+
new _Word64(0x3956c25b, 0xf348b538), new _Word64(0x59f111f1, 0xb605d019),
|
|
544
|
+
new _Word64(0x923f82a4, 0xaf194f9b), new _Word64(0xab1c5ed5, 0xda6d8118),
|
|
545
|
+
new _Word64(0xd807aa98, 0xa3030242), new _Word64(0x12835b01, 0x45706fbe),
|
|
546
|
+
new _Word64(0x243185be, 0x4ee4b28c), new _Word64(0x550c7dc3, 0xd5ffb4e2),
|
|
547
|
+
new _Word64(0x72be5d74, 0xf27b896f), new _Word64(0x80deb1fe, 0x3b1696b1),
|
|
548
|
+
new _Word64(0x9bdc06a7, 0x25c71235), new _Word64(0xc19bf174, 0xcf692694),
|
|
549
|
+
new _Word64(0xe49b69c1, 0x9ef14ad2), new _Word64(0xefbe4786, 0x384f25e3),
|
|
550
|
+
new _Word64(0x0fc19dc6, 0x8b8cd5b5), new _Word64(0x240ca1cc, 0x77ac9c65),
|
|
551
|
+
new _Word64(0x2de92c6f, 0x592b0275), new _Word64(0x4a7484aa, 0x6ea6e483),
|
|
552
|
+
new _Word64(0x5cb0a9dc, 0xbd41fbd4), new _Word64(0x76f988da, 0x831153b5),
|
|
553
|
+
new _Word64(0x983e5152, 0xee66dfab), new _Word64(0xa831c66d, 0x2db43210),
|
|
554
|
+
new _Word64(0xb00327c8, 0x98fb213f), new _Word64(0xbf597fc7, 0xbeef0ee4),
|
|
555
|
+
new _Word64(0xc6e00bf3, 0x3da88fc2), new _Word64(0xd5a79147, 0x930aa725),
|
|
556
|
+
new _Word64(0x06ca6351, 0xe003826f), new _Word64(0x14292967, 0x0a0e6e70),
|
|
557
|
+
new _Word64(0x27b70a85, 0x46d22ffc), new _Word64(0x2e1b2138, 0x5c26c926),
|
|
558
|
+
new _Word64(0x4d2c6dfc, 0x5ac42aed), new _Word64(0x53380d13, 0x9d95b3df),
|
|
559
|
+
new _Word64(0x650a7354, 0x8baf63de), new _Word64(0x766a0abb, 0x3c77b2a8),
|
|
560
|
+
new _Word64(0x81c2c92e, 0x47edaee6), new _Word64(0x92722c85, 0x1482353b),
|
|
561
|
+
new _Word64(0xa2bfe8a1, 0x4cf10364), new _Word64(0xa81a664b, 0xbc423001),
|
|
562
|
+
new _Word64(0xc24b8b70, 0xd0f89791), new _Word64(0xc76c51a3, 0x0654be30),
|
|
563
|
+
new _Word64(0xd192e819, 0xd6ef5218), new _Word64(0xd6990624, 0x5565a910),
|
|
564
|
+
new _Word64(0xf40e3585, 0x5771202a), new _Word64(0x106aa070, 0x32bbd1b8),
|
|
565
|
+
new _Word64(0x19a4c116, 0xb8d2d0c8), new _Word64(0x1e376c08, 0x5141ab53),
|
|
566
|
+
new _Word64(0x2748774c, 0xdf8eeb99), new _Word64(0x34b0bcb5, 0xe19b48a8),
|
|
567
|
+
new _Word64(0x391c0cb3, 0xc5c95a63), new _Word64(0x4ed8aa4a, 0xe3418acb),
|
|
568
|
+
new _Word64(0x5b9cca4f, 0x7763e373), new _Word64(0x682e6ff3, 0xd6b2b8a3),
|
|
569
|
+
new _Word64(0x748f82ee, 0x5defb2fc), new _Word64(0x78a5636f, 0x43172f60),
|
|
570
|
+
new _Word64(0x84c87814, 0xa1f0ab72), new _Word64(0x8cc70208, 0x1a6439ec),
|
|
571
|
+
new _Word64(0x90befffa, 0x23631e28), new _Word64(0xa4506ceb, 0xde82bde9),
|
|
572
|
+
new _Word64(0xbef9a3f7, 0xb2c67915), new _Word64(0xc67178f2, 0xe372532b),
|
|
573
|
+
new _Word64(0xca273ece, 0xea26619c), new _Word64(0xd186b8c7, 0x21c0c207),
|
|
574
|
+
new _Word64(0xeada7dd6, 0xcde0eb1e), new _Word64(0xf57d4f7f, 0xee6ed178),
|
|
575
|
+
new _Word64(0x06f067aa, 0x72176fba), new _Word64(0x0a637dc5, 0xa2c898a6),
|
|
576
|
+
new _Word64(0x113f9804, 0xbef90dae), new _Word64(0x1b710b35, 0x131c471b),
|
|
577
|
+
new _Word64(0x28db77f5, 0x23047d84), new _Word64(0x32caab7b, 0x40c72493),
|
|
578
|
+
new _Word64(0x3c9ebe0a, 0x15c9bebc), new _Word64(0x431d67c4, 0x9c100d4c),
|
|
579
|
+
new _Word64(0x4cc5d4be, 0xcb3e42b6), new _Word64(0x597f299c, 0xfc657e2a),
|
|
580
|
+
new _Word64(0x5fcb6fab, 0x3ad6faec), new _Word64(0x6c44198c, 0x4a475817)];
|
|
581
|
+
}
|
|
582
|
+
_Sha512.prototype._sigma = function (result, x, buffer) {
|
|
583
|
+
result.assign(x);
|
|
584
|
+
result.rotateRight(28);
|
|
585
|
+
buffer.assign(x);
|
|
586
|
+
buffer.rotateRight(34);
|
|
587
|
+
result.xor(buffer);
|
|
588
|
+
buffer.assign(x);
|
|
589
|
+
buffer.rotateRight(39);
|
|
590
|
+
result.xor(buffer);
|
|
591
|
+
};
|
|
592
|
+
_Sha512.prototype._sigmaPrime = function (result, x, buffer) {
|
|
593
|
+
result.assign(x);
|
|
594
|
+
result.rotateRight(14);
|
|
595
|
+
buffer.assign(x);
|
|
596
|
+
buffer.rotateRight(18);
|
|
597
|
+
result.xor(buffer);
|
|
598
|
+
buffer.assign(x);
|
|
599
|
+
buffer.rotateRight(41);
|
|
600
|
+
result.xor(buffer);
|
|
601
|
+
};
|
|
602
|
+
_Sha512.prototype._littleSigma = function (result, x, buffer) {
|
|
603
|
+
result.assign(x);
|
|
604
|
+
result.rotateRight(1);
|
|
605
|
+
buffer.assign(x);
|
|
606
|
+
buffer.rotateRight(8);
|
|
607
|
+
result.xor(buffer);
|
|
608
|
+
buffer.assign(x);
|
|
609
|
+
buffer.shiftRight(7);
|
|
610
|
+
result.xor(buffer);
|
|
611
|
+
};
|
|
612
|
+
_Sha512.prototype._littleSigmaPrime = function (result, x, buffer) {
|
|
613
|
+
result.assign(x);
|
|
614
|
+
result.rotateRight(19);
|
|
615
|
+
buffer.assign(x);
|
|
616
|
+
buffer.rotateRight(61);
|
|
617
|
+
result.xor(buffer);
|
|
618
|
+
buffer.assign(x);
|
|
619
|
+
buffer.shiftRight(6);
|
|
620
|
+
result.xor(buffer);
|
|
621
|
+
};
|
|
622
|
+
_Sha512.prototype._hash = function (data, offset, length, isMode384) {
|
|
623
|
+
if (isMode384 === void 0) { isMode384 = false; }
|
|
624
|
+
var h0;
|
|
625
|
+
var h1;
|
|
626
|
+
var h2;
|
|
627
|
+
var h3;
|
|
628
|
+
var h4;
|
|
629
|
+
var h5;
|
|
630
|
+
var h6;
|
|
631
|
+
var h7;
|
|
632
|
+
if (isMode384) {
|
|
633
|
+
h0 = new _Word64(0xcbbb9d5d, 0xc1059ed8);
|
|
634
|
+
h1 = new _Word64(0x629a292a, 0x367cd507);
|
|
635
|
+
h2 = new _Word64(0x9159015a, 0x3070dd17);
|
|
636
|
+
h3 = new _Word64(0x152fecd8, 0xf70e5939);
|
|
637
|
+
h4 = new _Word64(0x67332667, 0xffc00b31);
|
|
638
|
+
h5 = new _Word64(0x8eb44a87, 0x68581511);
|
|
639
|
+
h6 = new _Word64(0xdb0c2e0d, 0x64f98fa7);
|
|
640
|
+
h7 = new _Word64(0x47b5481d, 0xbefa4fa4);
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
h0 = new _Word64(0x6a09e667, 0xf3bcc908);
|
|
644
|
+
h1 = new _Word64(0xbb67ae85, 0x84caa73b);
|
|
645
|
+
h2 = new _Word64(0x3c6ef372, 0xfe94f82b);
|
|
646
|
+
h3 = new _Word64(0xa54ff53a, 0x5f1d36f1);
|
|
647
|
+
h4 = new _Word64(0x510e527f, 0xade682d1);
|
|
648
|
+
h5 = new _Word64(0x9b05688c, 0x2b3e6c1f);
|
|
649
|
+
h6 = new _Word64(0x1f83d9ab, 0xfb41bd6b);
|
|
650
|
+
h7 = new _Word64(0x5be0cd19, 0x137e2179);
|
|
651
|
+
}
|
|
652
|
+
var paddedLength = Math.ceil((length + 17) / 128) * 128;
|
|
653
|
+
var padded = new Uint8Array(paddedLength);
|
|
654
|
+
var i;
|
|
655
|
+
for (i = 0; i < length; ++i) {
|
|
656
|
+
padded[Number.parseInt(i.toString(), 10)] = data[offset++];
|
|
657
|
+
}
|
|
658
|
+
padded[i++] = 0x80;
|
|
659
|
+
var n = paddedLength - 16;
|
|
660
|
+
while (i < n) {
|
|
661
|
+
padded[i++] = 0;
|
|
662
|
+
}
|
|
663
|
+
padded[i++] = 0;
|
|
664
|
+
padded[i++] = 0;
|
|
665
|
+
padded[i++] = 0;
|
|
666
|
+
padded[i++] = 0;
|
|
667
|
+
padded[i++] = 0;
|
|
668
|
+
padded[i++] = 0;
|
|
669
|
+
padded[i++] = 0;
|
|
670
|
+
padded[i++] = 0;
|
|
671
|
+
padded[i++] = 0;
|
|
672
|
+
padded[i++] = 0;
|
|
673
|
+
padded[i++] = 0;
|
|
674
|
+
padded[i++] = (length >>> 29) & 0xff;
|
|
675
|
+
padded[i++] = (length >> 21) & 0xff;
|
|
676
|
+
padded[i++] = (length >> 13) & 0xff;
|
|
677
|
+
padded[i++] = (length >> 5) & 0xff;
|
|
678
|
+
padded[i++] = (length << 3) & 0xff;
|
|
679
|
+
var w = new Array(80);
|
|
680
|
+
for (i = 0; i < 80; i++) {
|
|
681
|
+
w[Number.parseInt(i.toString(), 10)] = new _Word64(0, 0);
|
|
682
|
+
}
|
|
683
|
+
var a = new _Word64(0, 0);
|
|
684
|
+
var b = new _Word64(0, 0);
|
|
685
|
+
var c = new _Word64(0, 0);
|
|
686
|
+
var d = new _Word64(0, 0);
|
|
687
|
+
var e = new _Word64(0, 0);
|
|
688
|
+
var f = new _Word64(0, 0);
|
|
689
|
+
var g = new _Word64(0, 0);
|
|
690
|
+
var h = new _Word64(0, 0);
|
|
691
|
+
var t1 = new _Word64(0, 0);
|
|
692
|
+
var t2 = new _Word64(0, 0);
|
|
693
|
+
var buffer1 = new _Word64(0, 0);
|
|
694
|
+
var buffer2 = new _Word64(0, 0);
|
|
695
|
+
var buffer3;
|
|
696
|
+
for (i = 0; i < paddedLength;) {
|
|
697
|
+
var j = void 0;
|
|
698
|
+
for (j = 0; j < 16; ++j) {
|
|
699
|
+
w[Number.parseInt(j.toString(), 10)].high =
|
|
700
|
+
(padded[Number.parseInt(i.toString(), 10)] << 24) |
|
|
701
|
+
(padded[i + 1] << 16) |
|
|
702
|
+
(padded[i + 2] << 8) |
|
|
703
|
+
padded[i + 3];
|
|
704
|
+
w[Number.parseInt(j.toString(), 10)].low =
|
|
705
|
+
(padded[i + 4] << 24) |
|
|
706
|
+
(padded[i + 5] << 16) |
|
|
707
|
+
(padded[i + 6] << 8) |
|
|
708
|
+
padded[i + 7];
|
|
709
|
+
i += 8;
|
|
710
|
+
}
|
|
711
|
+
for (j = 16; j < 80; ++j) {
|
|
712
|
+
buffer3 = w[Number.parseInt(j.toString(), 10)];
|
|
713
|
+
this._littleSigmaPrime(buffer3, w[j - 2], buffer2);
|
|
714
|
+
buffer3.add(w[j - 7]);
|
|
715
|
+
this._littleSigma(buffer1, w[j - 15], buffer2);
|
|
716
|
+
buffer3.add(buffer1);
|
|
717
|
+
buffer3.add(w[j - 16]);
|
|
718
|
+
}
|
|
719
|
+
a.assign(h0);
|
|
720
|
+
b.assign(h1);
|
|
721
|
+
c.assign(h2);
|
|
722
|
+
d.assign(h3);
|
|
723
|
+
e.assign(h4);
|
|
724
|
+
f.assign(h5);
|
|
725
|
+
g.assign(h6);
|
|
726
|
+
h.assign(h7);
|
|
727
|
+
for (j = 0; j < 80; ++j) {
|
|
728
|
+
t1.assign(h);
|
|
729
|
+
this._sigmaPrime(buffer1, e, buffer2);
|
|
730
|
+
t1.add(buffer1);
|
|
731
|
+
buffer1.assign(e);
|
|
732
|
+
buffer1.and(f);
|
|
733
|
+
buffer2.assign(e);
|
|
734
|
+
buffer2.not();
|
|
735
|
+
buffer2.and(g);
|
|
736
|
+
buffer1.xor(buffer2);
|
|
737
|
+
t1.add(buffer1);
|
|
738
|
+
t1.add(this._k[Number.parseInt(j.toString(), 10)]);
|
|
739
|
+
t1.add(w[Number.parseInt(j.toString(), 10)]);
|
|
740
|
+
this._sigma(t2, a, buffer2);
|
|
741
|
+
buffer1.assign(a);
|
|
742
|
+
buffer1.and(b);
|
|
743
|
+
buffer2.assign(a);
|
|
744
|
+
buffer2.and(c);
|
|
745
|
+
buffer1.xor(buffer2);
|
|
746
|
+
buffer2.assign(b);
|
|
747
|
+
buffer2.and(c);
|
|
748
|
+
buffer1.xor(buffer2);
|
|
749
|
+
t2.add(buffer1);
|
|
750
|
+
buffer3 = h;
|
|
751
|
+
h = g;
|
|
752
|
+
g = f;
|
|
753
|
+
f = e;
|
|
754
|
+
d.add(t1);
|
|
755
|
+
e = d;
|
|
756
|
+
d = c;
|
|
757
|
+
c = b;
|
|
758
|
+
b = a;
|
|
759
|
+
buffer3.assign(t1);
|
|
760
|
+
buffer3.add(t2);
|
|
761
|
+
a = buffer3;
|
|
762
|
+
}
|
|
763
|
+
h0.add(a);
|
|
764
|
+
h1.add(b);
|
|
765
|
+
h2.add(c);
|
|
766
|
+
h3.add(d);
|
|
767
|
+
h4.add(e);
|
|
768
|
+
h5.add(f);
|
|
769
|
+
h6.add(g);
|
|
770
|
+
h7.add(h);
|
|
771
|
+
}
|
|
772
|
+
var result;
|
|
773
|
+
if (!isMode384) {
|
|
774
|
+
result = new Uint8Array(64);
|
|
775
|
+
h0.copyTo(result, 0);
|
|
776
|
+
h1.copyTo(result, 8);
|
|
777
|
+
h2.copyTo(result, 16);
|
|
778
|
+
h3.copyTo(result, 24);
|
|
779
|
+
h4.copyTo(result, 32);
|
|
780
|
+
h5.copyTo(result, 40);
|
|
781
|
+
h6.copyTo(result, 48);
|
|
782
|
+
h7.copyTo(result, 56);
|
|
783
|
+
}
|
|
784
|
+
else {
|
|
785
|
+
result = new Uint8Array(48);
|
|
786
|
+
h0.copyTo(result, 0);
|
|
787
|
+
h1.copyTo(result, 8);
|
|
788
|
+
h2.copyTo(result, 16);
|
|
789
|
+
h3.copyTo(result, 24);
|
|
790
|
+
h4.copyTo(result, 32);
|
|
791
|
+
h5.copyTo(result, 40);
|
|
792
|
+
}
|
|
793
|
+
return result;
|
|
794
|
+
};
|
|
795
|
+
return _Sha512;
|
|
796
|
+
}());
|
|
797
|
+
export { _Sha512 };
|
|
798
|
+
var _Word64 = /** @class */ (function () {
|
|
799
|
+
function _Word64(high, low) {
|
|
800
|
+
this.high = high | 0;
|
|
801
|
+
this.low = low | 0;
|
|
802
|
+
}
|
|
803
|
+
_Word64.prototype.and = function (word) {
|
|
804
|
+
this.high &= word.high;
|
|
805
|
+
this.low &= word.low;
|
|
806
|
+
};
|
|
807
|
+
_Word64.prototype.or = function (word) {
|
|
808
|
+
this.high |= word.high;
|
|
809
|
+
this.low |= word.low;
|
|
810
|
+
};
|
|
811
|
+
_Word64.prototype.not = function () {
|
|
812
|
+
this.high = ~this.high;
|
|
813
|
+
this.low = ~this.low;
|
|
814
|
+
};
|
|
815
|
+
_Word64.prototype.xor = function (word) {
|
|
816
|
+
this.high ^= word.high;
|
|
817
|
+
this.low ^= word.low;
|
|
818
|
+
};
|
|
819
|
+
_Word64.prototype.shiftRight = function (places) {
|
|
820
|
+
if (places >= 32) {
|
|
821
|
+
this.low = (this.high >>> (places - 32)) | 0;
|
|
822
|
+
this.high = 0;
|
|
823
|
+
}
|
|
824
|
+
else {
|
|
825
|
+
this.low = (this.low >>> places) | (this.high << (32 - places));
|
|
826
|
+
this.high = (this.high >>> places) | 0;
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
_Word64.prototype.shiftLeft = function (places) {
|
|
830
|
+
if (places >= 32) {
|
|
831
|
+
this.high = this.low << (places - 32);
|
|
832
|
+
this.low = 0;
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
this.high = (this.high << places) | (this.low >>> (32 - places));
|
|
836
|
+
this.low <<= places;
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
_Word64.prototype.rotateRight = function (places) {
|
|
840
|
+
var low;
|
|
841
|
+
var high;
|
|
842
|
+
if (places & 32) {
|
|
843
|
+
high = this.low;
|
|
844
|
+
low = this.high;
|
|
845
|
+
}
|
|
846
|
+
else {
|
|
847
|
+
low = this.low;
|
|
848
|
+
high = this.high;
|
|
849
|
+
}
|
|
850
|
+
places &= 31;
|
|
851
|
+
this.low = (low >>> places) | (high << (32 - places));
|
|
852
|
+
this.high = (high >>> places) | (low << (32 - places));
|
|
853
|
+
};
|
|
854
|
+
_Word64.prototype.add = function (word) {
|
|
855
|
+
var lowAdd = (this.low >>> 0) + (word.low >>> 0);
|
|
856
|
+
var highAdd = (this.high >>> 0) + (word.high >>> 0);
|
|
857
|
+
if (lowAdd > 0xffffffff) {
|
|
858
|
+
highAdd += 1;
|
|
859
|
+
}
|
|
860
|
+
this.low = lowAdd | 0;
|
|
861
|
+
this.high = highAdd | 0;
|
|
862
|
+
};
|
|
863
|
+
_Word64.prototype.copyTo = function (bytes, offset) {
|
|
864
|
+
bytes[Number.parseInt(offset.toString(), 10)] = (this.high >>> 24) & 0xff;
|
|
865
|
+
bytes[offset + 1] = (this.high >> 16) & 0xff;
|
|
866
|
+
bytes[offset + 2] = (this.high >> 8) & 0xff;
|
|
867
|
+
bytes[offset + 3] = this.high & 0xff;
|
|
868
|
+
bytes[offset + 4] = (this.low >>> 24) & 0xff;
|
|
869
|
+
bytes[offset + 5] = (this.low >> 16) & 0xff;
|
|
870
|
+
bytes[offset + 6] = (this.low >> 8) & 0xff;
|
|
871
|
+
bytes[offset + 7] = this.low & 0xff;
|
|
872
|
+
};
|
|
873
|
+
_Word64.prototype.assign = function (word) {
|
|
874
|
+
this.high = word.high;
|
|
875
|
+
this.low = word.low;
|
|
876
|
+
};
|
|
877
|
+
return _Word64;
|
|
878
|
+
}());
|
|
879
|
+
export { _Word64 };
|
|
880
|
+
var _EncryptionKey = /** @class */ (function () {
|
|
881
|
+
function _EncryptionKey() {
|
|
882
|
+
}
|
|
883
|
+
Object.defineProperty(_EncryptionKey.prototype, "_sha256", {
|
|
884
|
+
get: function () {
|
|
885
|
+
if (typeof this._sha256Obj === 'undefined') {
|
|
886
|
+
this._sha256Obj = new _Sha256();
|
|
887
|
+
}
|
|
888
|
+
return this._sha256Obj;
|
|
889
|
+
},
|
|
890
|
+
enumerable: true,
|
|
891
|
+
configurable: true
|
|
892
|
+
});
|
|
893
|
+
Object.defineProperty(_EncryptionKey.prototype, "_sha512", {
|
|
894
|
+
get: function () {
|
|
895
|
+
if (typeof this._sha512Obj === 'undefined') {
|
|
896
|
+
this._sha512Obj = new _Sha512();
|
|
897
|
+
}
|
|
898
|
+
return this._sha512Obj;
|
|
899
|
+
},
|
|
900
|
+
enumerable: true,
|
|
901
|
+
configurable: true
|
|
902
|
+
});
|
|
903
|
+
return _EncryptionKey;
|
|
904
|
+
}());
|
|
905
|
+
export { _EncryptionKey };
|
|
906
|
+
// PDF17 encryption support
|
|
907
|
+
var _BasicEncryption = /** @class */ (function (_super) {
|
|
908
|
+
__extends(_BasicEncryption, _super);
|
|
909
|
+
function _BasicEncryption() {
|
|
910
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
911
|
+
}
|
|
912
|
+
_BasicEncryption.prototype._checkOwnerPassword = function (password, ownerValidationSalt, userBytes, ownerPassword) {
|
|
913
|
+
var hashData = new Uint8Array(password.length + 56);
|
|
914
|
+
hashData.set(password, 0);
|
|
915
|
+
hashData.set(ownerValidationSalt, password.length);
|
|
916
|
+
hashData.set(userBytes, password.length + ownerValidationSalt.length);
|
|
917
|
+
var result = this._sha256._hash(hashData, 0, hashData.length);
|
|
918
|
+
return _areArrayEqual(result, ownerPassword);
|
|
919
|
+
};
|
|
920
|
+
_BasicEncryption.prototype._checkUserPassword = function (password, userValidationSalt, userPassword) {
|
|
921
|
+
var hashData = new Uint8Array(password.length + 8);
|
|
922
|
+
hashData.set(password, 0);
|
|
923
|
+
hashData.set(userValidationSalt, password.length);
|
|
924
|
+
var result = this._sha256._hash(hashData, 0, hashData.length);
|
|
925
|
+
return _areArrayEqual(result, userPassword);
|
|
926
|
+
};
|
|
927
|
+
_BasicEncryption.prototype._getOwnerKey = function (password, ownerKeySalt, userBytes, ownerEncryption) {
|
|
928
|
+
var hashData = new Uint8Array(password.length + 56);
|
|
929
|
+
hashData.set(password, 0);
|
|
930
|
+
hashData.set(ownerKeySalt, password.length);
|
|
931
|
+
hashData.set(userBytes, password.length + ownerKeySalt.length);
|
|
932
|
+
var key = this._sha256._hash(hashData, 0, hashData.length);
|
|
933
|
+
return (new _AdvancedEncryption256Cipher(key))._decryptBlock(ownerEncryption, false, new Uint8Array(16));
|
|
934
|
+
};
|
|
935
|
+
_BasicEncryption.prototype._getUserKey = function (password, userKeySalt, userEncryption) {
|
|
936
|
+
var hashData = new Uint8Array(password.length + 8);
|
|
937
|
+
hashData.set(password, 0);
|
|
938
|
+
hashData.set(userKeySalt, password.length);
|
|
939
|
+
var key = this._sha256._hash(hashData, 0, hashData.length);
|
|
940
|
+
return (new _AdvancedEncryption256Cipher(key))._decryptBlock(userEncryption, false, new Uint8Array(16));
|
|
941
|
+
};
|
|
942
|
+
return _BasicEncryption;
|
|
943
|
+
}(_EncryptionKey));
|
|
944
|
+
export { _BasicEncryption };
|
|
945
|
+
// PDF20 encryption support
|
|
946
|
+
var _AdvancedEncryption = /** @class */ (function (_super) {
|
|
947
|
+
__extends(_AdvancedEncryption, _super);
|
|
948
|
+
function _AdvancedEncryption() {
|
|
949
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
950
|
+
}
|
|
951
|
+
_AdvancedEncryption.prototype._checkOwnerPassword = function (password, ownerValidationSalt, userBytes, ownerPassword) {
|
|
952
|
+
var hashData = new Uint8Array(password.length + 56);
|
|
953
|
+
hashData.set(password, 0);
|
|
954
|
+
hashData.set(ownerValidationSalt, password.length);
|
|
955
|
+
hashData.set(userBytes, password.length + ownerValidationSalt.length);
|
|
956
|
+
var result = this._hash(password, hashData, userBytes);
|
|
957
|
+
return _areArrayEqual(result, ownerPassword);
|
|
958
|
+
};
|
|
959
|
+
_AdvancedEncryption.prototype._checkUserPassword = function (password, userValidationSalt, userPassword) {
|
|
960
|
+
var hashData = new Uint8Array(password.length + 8);
|
|
961
|
+
hashData.set(password, 0);
|
|
962
|
+
hashData.set(userValidationSalt, password.length);
|
|
963
|
+
var result = this._hash(password, hashData, new Uint8Array([]));
|
|
964
|
+
return _areArrayEqual(result, userPassword);
|
|
965
|
+
};
|
|
966
|
+
_AdvancedEncryption.prototype._getOwnerKey = function (password, ownerKeySalt, userBytes, ownerEncryption) {
|
|
967
|
+
var hashData = new Uint8Array(password.length + 56);
|
|
968
|
+
hashData.set(password, 0);
|
|
969
|
+
hashData.set(ownerKeySalt, password.length);
|
|
970
|
+
hashData.set(userBytes, password.length + ownerKeySalt.length);
|
|
971
|
+
var key = this._hash(password, hashData, userBytes);
|
|
972
|
+
return (new _AdvancedEncryption256Cipher(key))._decryptBlock(ownerEncryption, false, new Uint8Array(16));
|
|
973
|
+
};
|
|
974
|
+
_AdvancedEncryption.prototype._getUserKey = function (password, userKeySalt, userEncryption) {
|
|
975
|
+
var hashData = new Uint8Array(password.length + 8);
|
|
976
|
+
hashData.set(password, 0);
|
|
977
|
+
hashData.set(userKeySalt, password.length);
|
|
978
|
+
var key = this._hash(password, hashData, new Uint8Array([]));
|
|
979
|
+
var cipher = new _AdvancedEncryption256Cipher(key);
|
|
980
|
+
return cipher._decryptBlock(userEncryption, false, new Uint8Array(16));
|
|
981
|
+
};
|
|
982
|
+
_AdvancedEncryption.prototype._hash = function (password, input, userBytes) {
|
|
983
|
+
var data = this._sha256._hash(input, 0, input.length).subarray(0, 32);
|
|
984
|
+
var encrypted = new Uint8Array([0]);
|
|
985
|
+
var i = 0;
|
|
986
|
+
while (i < 64 || encrypted[encrypted.length - 1] > i - 32) {
|
|
987
|
+
var combinedLength = password.length + data.length + userBytes.length;
|
|
988
|
+
var combinedArray = new Uint8Array(combinedLength);
|
|
989
|
+
var writeOffset = 0;
|
|
990
|
+
combinedArray.set(password, writeOffset);
|
|
991
|
+
writeOffset += password.length;
|
|
992
|
+
combinedArray.set(data, writeOffset);
|
|
993
|
+
writeOffset += data.length;
|
|
994
|
+
combinedArray.set(userBytes, writeOffset);
|
|
995
|
+
var k1 = new Uint8Array(combinedLength * 64);
|
|
996
|
+
for (var j = 0, pos = 0; j < 64; j++) {
|
|
997
|
+
k1.set(combinedArray, pos);
|
|
998
|
+
pos += combinedLength;
|
|
999
|
+
}
|
|
1000
|
+
var cipher = new _AdvancedEncryption128Cipher(data.subarray(0, 16));
|
|
1001
|
+
encrypted = cipher._encrypt(k1, data.subarray(16, 32));
|
|
1002
|
+
var remainder = 0;
|
|
1003
|
+
for (var z = 0; z < 16; z++) {
|
|
1004
|
+
remainder *= 256 % 3;
|
|
1005
|
+
remainder %= 3;
|
|
1006
|
+
remainder += (encrypted[Number.parseInt(z.toString(), 10)] >>> 0) % 3;
|
|
1007
|
+
remainder %= 3;
|
|
1008
|
+
}
|
|
1009
|
+
if (remainder === 2) {
|
|
1010
|
+
data = this._sha512._hash(encrypted, 0, encrypted.length);
|
|
1011
|
+
}
|
|
1012
|
+
else if (remainder === 1) {
|
|
1013
|
+
data = this._sha512._hash(encrypted, 0, encrypted.length, true);
|
|
1014
|
+
}
|
|
1015
|
+
else if (remainder === 0) {
|
|
1016
|
+
data = this._sha256._hash(encrypted, 0, encrypted.length);
|
|
1017
|
+
}
|
|
1018
|
+
i++;
|
|
1019
|
+
}
|
|
1020
|
+
return data.subarray(0, 32);
|
|
1021
|
+
};
|
|
1022
|
+
return _AdvancedEncryption;
|
|
1023
|
+
}(_EncryptionKey));
|
|
1024
|
+
export { _AdvancedEncryption };
|
|
1025
|
+
var _Cipher = /** @class */ (function () {
|
|
1026
|
+
function _Cipher() {
|
|
1027
|
+
}
|
|
1028
|
+
return _Cipher;
|
|
1029
|
+
}());
|
|
1030
|
+
export { _Cipher };
|
|
1031
|
+
var _NormalCipherFour = /** @class */ (function (_super) {
|
|
1032
|
+
__extends(_NormalCipherFour, _super);
|
|
1033
|
+
function _NormalCipherFour(key) {
|
|
1034
|
+
var _this = _super.call(this) || this;
|
|
1035
|
+
_this._a = 0;
|
|
1036
|
+
_this._b = 0;
|
|
1037
|
+
var s = new Uint8Array(256);
|
|
1038
|
+
for (var i = 0; i < 256; ++i) {
|
|
1039
|
+
s[Number.parseInt(i.toString(), 10)] = i;
|
|
1040
|
+
}
|
|
1041
|
+
var keyLength = key.length;
|
|
1042
|
+
for (var i = 0, j = 0; i < 256; ++i) {
|
|
1043
|
+
var buffer = s[Number.parseInt(i.toString(), 10)];
|
|
1044
|
+
j = (j + buffer + key[i % keyLength]) & 0xff;
|
|
1045
|
+
s[Number.parseInt(i.toString(), 10)] = s[Number.parseInt(j.toString(), 10)];
|
|
1046
|
+
s[Number.parseInt(j.toString(), 10)] = buffer;
|
|
1047
|
+
}
|
|
1048
|
+
_this._s = s;
|
|
1049
|
+
return _this;
|
|
1050
|
+
}
|
|
1051
|
+
_NormalCipherFour.prototype._encryptBlock = function (data) {
|
|
1052
|
+
var a = this._a;
|
|
1053
|
+
var b = this._b;
|
|
1054
|
+
var s = this._s;
|
|
1055
|
+
var n = data.length;
|
|
1056
|
+
var output = new Uint8Array(n);
|
|
1057
|
+
for (var i = 0; i < n; ++i) {
|
|
1058
|
+
a = (a + 1) & 0xff;
|
|
1059
|
+
var first = s[Number.parseInt(a.toString(), 10)];
|
|
1060
|
+
b = (b + first) & 0xff;
|
|
1061
|
+
var second = s[Number.parseInt(b.toString(), 10)];
|
|
1062
|
+
s[Number.parseInt(a.toString(), 10)] = second;
|
|
1063
|
+
s[Number.parseInt(b.toString(), 10)] = first;
|
|
1064
|
+
output[Number.parseInt(i.toString(), 10)] = data[Number.parseInt(i.toString(), 10)] ^ s[(first + second) & 0xff];
|
|
1065
|
+
}
|
|
1066
|
+
this._a = a;
|
|
1067
|
+
this._b = b;
|
|
1068
|
+
return output;
|
|
1069
|
+
};
|
|
1070
|
+
_NormalCipherFour.prototype._decryptBlock = function (data) {
|
|
1071
|
+
return this._encryptBlock(data);
|
|
1072
|
+
};
|
|
1073
|
+
_NormalCipherFour.prototype._encrypt = function (data) {
|
|
1074
|
+
return this._encryptBlock(data);
|
|
1075
|
+
};
|
|
1076
|
+
return _NormalCipherFour;
|
|
1077
|
+
}(_Cipher));
|
|
1078
|
+
export { _NormalCipherFour };
|
|
1079
|
+
var _AdvancedEncryptionBaseCipher = /** @class */ (function (_super) {
|
|
1080
|
+
__extends(_AdvancedEncryptionBaseCipher, _super);
|
|
1081
|
+
function _AdvancedEncryptionBaseCipher() {
|
|
1082
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
1083
|
+
_this._buffer = new Uint8Array(16);
|
|
1084
|
+
_this._position = 0;
|
|
1085
|
+
_this._s = new Uint8Array([
|
|
1086
|
+
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
|
|
1087
|
+
0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
|
|
1088
|
+
0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
|
|
1089
|
+
0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
|
|
1090
|
+
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
|
|
1091
|
+
0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
|
|
1092
|
+
0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
|
|
1093
|
+
0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
|
|
1094
|
+
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
|
|
1095
|
+
0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
|
|
1096
|
+
0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
|
|
1097
|
+
0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
|
|
1098
|
+
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
|
|
1099
|
+
0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
|
|
1100
|
+
0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
|
|
1101
|
+
0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
|
|
1102
|
+
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
|
|
1103
|
+
0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
|
|
1104
|
+
0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
|
|
1105
|
+
0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
|
|
1106
|
+
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
|
|
1107
|
+
0xb0, 0x54, 0xbb, 0x16
|
|
1108
|
+
]);
|
|
1109
|
+
_this._inverseS = new Uint8Array([
|
|
1110
|
+
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
|
|
1111
|
+
0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
|
|
1112
|
+
0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
|
|
1113
|
+
0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
|
|
1114
|
+
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
|
|
1115
|
+
0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
|
|
1116
|
+
0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
|
|
1117
|
+
0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
|
|
1118
|
+
0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
|
|
1119
|
+
0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
|
|
1120
|
+
0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
|
|
1121
|
+
0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
|
|
1122
|
+
0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
|
|
1123
|
+
0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
|
|
1124
|
+
0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
|
|
1125
|
+
0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
|
|
1126
|
+
0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
|
|
1127
|
+
0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
|
|
1128
|
+
0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
|
|
1129
|
+
0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
|
|
1130
|
+
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
|
|
1131
|
+
0x55, 0x21, 0x0c, 0x7d
|
|
1132
|
+
]);
|
|
1133
|
+
_this._mix = new Uint32Array([
|
|
1134
|
+
0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
|
|
1135
|
+
0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
|
|
1136
|
+
0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
|
|
1137
|
+
0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
|
|
1138
|
+
0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
|
|
1139
|
+
0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
|
|
1140
|
+
0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
|
|
1141
|
+
0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
|
|
1142
|
+
0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
|
|
1143
|
+
0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
|
|
1144
|
+
0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
|
|
1145
|
+
0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
|
|
1146
|
+
0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
|
|
1147
|
+
0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
|
|
1148
|
+
0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
|
|
1149
|
+
0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
|
|
1150
|
+
0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
|
|
1151
|
+
0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
|
|
1152
|
+
0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
|
|
1153
|
+
0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
|
|
1154
|
+
0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
|
|
1155
|
+
0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
|
|
1156
|
+
0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
|
|
1157
|
+
0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
|
|
1158
|
+
0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
|
|
1159
|
+
0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
|
|
1160
|
+
0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
|
|
1161
|
+
0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
|
|
1162
|
+
0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
|
|
1163
|
+
0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
|
|
1164
|
+
0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
|
|
1165
|
+
0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
|
|
1166
|
+
0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
|
|
1167
|
+
0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
|
|
1168
|
+
0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
|
|
1169
|
+
0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
|
|
1170
|
+
0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
|
|
1171
|
+
0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
|
|
1172
|
+
0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
|
|
1173
|
+
0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
|
|
1174
|
+
0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
|
|
1175
|
+
0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
|
|
1176
|
+
0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3
|
|
1177
|
+
]);
|
|
1178
|
+
return _this;
|
|
1179
|
+
}
|
|
1180
|
+
Object.defineProperty(_AdvancedEncryptionBaseCipher.prototype, "_mixCol", {
|
|
1181
|
+
get: function () {
|
|
1182
|
+
if (typeof this._mixC === 'undefined') {
|
|
1183
|
+
this._mixC = new Uint8Array(256);
|
|
1184
|
+
for (var i = 0; i < 256; i++) {
|
|
1185
|
+
if (i < 128) {
|
|
1186
|
+
this._mixC[Number.parseInt(i.toString(), 10)] = i << 1;
|
|
1187
|
+
}
|
|
1188
|
+
else {
|
|
1189
|
+
this._mixC[Number.parseInt(i.toString(), 10)] = (i << 1) ^ 0x1b;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
return this._mixC;
|
|
1194
|
+
},
|
|
1195
|
+
enumerable: true,
|
|
1196
|
+
configurable: true
|
|
1197
|
+
});
|
|
1198
|
+
_AdvancedEncryptionBaseCipher.prototype._decrypt = function (input, key) {
|
|
1199
|
+
var t;
|
|
1200
|
+
var u;
|
|
1201
|
+
var v;
|
|
1202
|
+
var state = new Uint8Array(16);
|
|
1203
|
+
state.set(input);
|
|
1204
|
+
for (var j = 0, k = this._keySize; j < 16; ++j, ++k) {
|
|
1205
|
+
state[Number.parseInt(j.toString(), 10)] ^= key[Number.parseInt(k.toString(), 10)];
|
|
1206
|
+
}
|
|
1207
|
+
for (var i = this._cyclesOfRepetition - 1; i >= 1; --i) {
|
|
1208
|
+
t = state[13];
|
|
1209
|
+
state[13] = state[9];
|
|
1210
|
+
state[9] = state[5];
|
|
1211
|
+
state[5] = state[1];
|
|
1212
|
+
state[1] = t;
|
|
1213
|
+
t = state[14];
|
|
1214
|
+
u = state[10];
|
|
1215
|
+
state[14] = state[6];
|
|
1216
|
+
state[10] = state[2];
|
|
1217
|
+
state[6] = t;
|
|
1218
|
+
state[2] = u;
|
|
1219
|
+
t = state[15];
|
|
1220
|
+
u = state[11];
|
|
1221
|
+
v = state[7];
|
|
1222
|
+
state[15] = state[3];
|
|
1223
|
+
state[11] = t;
|
|
1224
|
+
state[7] = u;
|
|
1225
|
+
state[3] = v;
|
|
1226
|
+
for (var j = 0; j < 16; ++j) {
|
|
1227
|
+
state[Number.parseInt(j.toString(), 10)] = this._inverseS[state[Number.parseInt(j.toString(), 10)]];
|
|
1228
|
+
}
|
|
1229
|
+
for (var j = 0, k = i * 16; j < 16; ++j, ++k) {
|
|
1230
|
+
state[Number.parseInt(j.toString(), 10)] ^= key[Number.parseInt(k.toString(), 10)];
|
|
1231
|
+
}
|
|
1232
|
+
for (var j = 0; j < 16; j += 4) {
|
|
1233
|
+
var s0 = this._mix[state[Number.parseInt(j.toString(), 10)]];
|
|
1234
|
+
var s1 = this._mix[state[j + 1]];
|
|
1235
|
+
var s2 = this._mix[state[j + 2]];
|
|
1236
|
+
var s3 = this._mix[state[j + 3]];
|
|
1237
|
+
t = s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^ (s3 >>> 24) ^ (s3 << 8);
|
|
1238
|
+
state[Number.parseInt(j.toString(), 10)] = (t >>> 24) & 0xff;
|
|
1239
|
+
state[j + 1] = (t >> 16) & 0xff;
|
|
1240
|
+
state[j + 2] = (t >> 8) & 0xff;
|
|
1241
|
+
state[j + 3] = t & 0xff;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
t = state[13];
|
|
1245
|
+
state[13] = state[9];
|
|
1246
|
+
state[9] = state[5];
|
|
1247
|
+
state[5] = state[1];
|
|
1248
|
+
state[1] = t;
|
|
1249
|
+
t = state[14];
|
|
1250
|
+
u = state[10];
|
|
1251
|
+
state[14] = state[6];
|
|
1252
|
+
state[10] = state[2];
|
|
1253
|
+
state[6] = t;
|
|
1254
|
+
state[2] = u;
|
|
1255
|
+
t = state[15];
|
|
1256
|
+
u = state[11];
|
|
1257
|
+
v = state[7];
|
|
1258
|
+
state[15] = state[3];
|
|
1259
|
+
state[11] = t;
|
|
1260
|
+
state[7] = u;
|
|
1261
|
+
state[3] = v;
|
|
1262
|
+
for (var j = 0; j < 16; ++j) {
|
|
1263
|
+
state[Number.parseInt(j.toString(), 10)] = this._inverseS[state[Number.parseInt(j.toString(), 10)]];
|
|
1264
|
+
state[Number.parseInt(j.toString(), 10)] ^= key[Number.parseInt(j.toString(), 10)];
|
|
1265
|
+
}
|
|
1266
|
+
return state;
|
|
1267
|
+
};
|
|
1268
|
+
_AdvancedEncryptionBaseCipher.prototype._encryptBlock = function (input, key) {
|
|
1269
|
+
var s = this._s;
|
|
1270
|
+
var t;
|
|
1271
|
+
var u;
|
|
1272
|
+
var v;
|
|
1273
|
+
var state = new Uint8Array(16);
|
|
1274
|
+
state.set(input);
|
|
1275
|
+
for (var j = 0; j < 16; ++j) {
|
|
1276
|
+
state[Number.parseInt(j.toString(), 10)] ^= key[Number.parseInt(j.toString(), 10)];
|
|
1277
|
+
}
|
|
1278
|
+
for (var i = 1; i < this._cyclesOfRepetition; i++) {
|
|
1279
|
+
for (var j = 0; j < 16; ++j) {
|
|
1280
|
+
state[Number.parseInt(j.toString(), 10)] = s[state[Number.parseInt(j.toString(), 10)]];
|
|
1281
|
+
}
|
|
1282
|
+
v = state[1];
|
|
1283
|
+
state[1] = state[5];
|
|
1284
|
+
state[5] = state[9];
|
|
1285
|
+
state[9] = state[13];
|
|
1286
|
+
state[13] = v;
|
|
1287
|
+
v = state[2];
|
|
1288
|
+
u = state[6];
|
|
1289
|
+
state[2] = state[10];
|
|
1290
|
+
state[6] = state[14];
|
|
1291
|
+
state[10] = v;
|
|
1292
|
+
state[14] = u;
|
|
1293
|
+
v = state[3];
|
|
1294
|
+
u = state[7];
|
|
1295
|
+
t = state[11];
|
|
1296
|
+
state[3] = state[15];
|
|
1297
|
+
state[7] = v;
|
|
1298
|
+
state[11] = u;
|
|
1299
|
+
state[15] = t;
|
|
1300
|
+
for (var j = 0; j < 16; j += 4) {
|
|
1301
|
+
var s0 = state[j + 0];
|
|
1302
|
+
var s1 = state[j + 1];
|
|
1303
|
+
var s2 = state[j + 2];
|
|
1304
|
+
var s3 = state[j + 3];
|
|
1305
|
+
t = s0 ^ s1 ^ s2 ^ s3;
|
|
1306
|
+
state[j + 0] ^= t ^ this._mixCol[s0 ^ s1];
|
|
1307
|
+
state[j + 1] ^= t ^ this._mixCol[s1 ^ s2];
|
|
1308
|
+
state[j + 2] ^= t ^ this._mixCol[s2 ^ s3];
|
|
1309
|
+
state[j + 3] ^= t ^ this._mixCol[s3 ^ s0];
|
|
1310
|
+
}
|
|
1311
|
+
for (var j = 0, k = i * 16; j < 16; ++j, ++k) {
|
|
1312
|
+
state[Number.parseInt(j.toString(), 10)] ^= key[Number.parseInt(k.toString(), 10)];
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
for (var j = 0; j < 16; ++j) {
|
|
1316
|
+
state[Number.parseInt(j.toString(), 10)] = s[state[Number.parseInt(j.toString(), 10)]];
|
|
1317
|
+
}
|
|
1318
|
+
v = state[1];
|
|
1319
|
+
state[1] = state[5];
|
|
1320
|
+
state[5] = state[9];
|
|
1321
|
+
state[9] = state[13];
|
|
1322
|
+
state[13] = v;
|
|
1323
|
+
v = state[2];
|
|
1324
|
+
u = state[6];
|
|
1325
|
+
state[2] = state[10];
|
|
1326
|
+
state[6] = state[14];
|
|
1327
|
+
state[10] = v;
|
|
1328
|
+
state[14] = u;
|
|
1329
|
+
v = state[3];
|
|
1330
|
+
u = state[7];
|
|
1331
|
+
t = state[11];
|
|
1332
|
+
state[3] = state[15];
|
|
1333
|
+
state[7] = v;
|
|
1334
|
+
state[11] = u;
|
|
1335
|
+
state[15] = t;
|
|
1336
|
+
for (var j = 0, k = this._keySize; j < 16; ++j, ++k) {
|
|
1337
|
+
state[Number.parseInt(j.toString(), 10)] ^= key[Number.parseInt(k.toString(), 10)];
|
|
1338
|
+
}
|
|
1339
|
+
return state;
|
|
1340
|
+
};
|
|
1341
|
+
_AdvancedEncryptionBaseCipher.prototype._decryptBlockHelper = function (data, finalize) {
|
|
1342
|
+
var sourceLength = data.length;
|
|
1343
|
+
var buffer = this._buffer;
|
|
1344
|
+
var bufferLength = this._position;
|
|
1345
|
+
var result = [];
|
|
1346
|
+
var iv = this._iv;
|
|
1347
|
+
for (var i = 0; i < sourceLength; ++i) {
|
|
1348
|
+
buffer[Number.parseInt(bufferLength.toString(), 10)] = data[Number.parseInt(i.toString(), 10)];
|
|
1349
|
+
++bufferLength;
|
|
1350
|
+
if (bufferLength < 16) {
|
|
1351
|
+
continue;
|
|
1352
|
+
}
|
|
1353
|
+
var plain = this._decrypt(buffer, this._key);
|
|
1354
|
+
for (var j = 0; j < 16; ++j) {
|
|
1355
|
+
plain[Number.parseInt(j.toString(), 10)] ^= iv[Number.parseInt(j.toString(), 10)];
|
|
1356
|
+
}
|
|
1357
|
+
iv = buffer;
|
|
1358
|
+
result.push(plain);
|
|
1359
|
+
buffer = new Uint8Array(16);
|
|
1360
|
+
bufferLength = 0;
|
|
1361
|
+
}
|
|
1362
|
+
this._buffer = buffer;
|
|
1363
|
+
this._bufferLength = bufferLength;
|
|
1364
|
+
this._iv = iv;
|
|
1365
|
+
if (result.length === 0) {
|
|
1366
|
+
return new Uint8Array(0);
|
|
1367
|
+
}
|
|
1368
|
+
var outputLength = 16 * result.length;
|
|
1369
|
+
if (finalize) {
|
|
1370
|
+
var lastBlock = result[result.length - 1];
|
|
1371
|
+
var length_1 = lastBlock[15];
|
|
1372
|
+
if (length_1 <= 16) {
|
|
1373
|
+
for (var i = 15, ii = 16 - length_1; i >= ii; --i) {
|
|
1374
|
+
if (lastBlock[Number.parseInt(i.toString(), 10)] !== length_1) {
|
|
1375
|
+
length_1 = 0;
|
|
1376
|
+
break;
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
outputLength -= length_1;
|
|
1380
|
+
result[result.length - 1] = lastBlock.subarray(0, 16 - length_1);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
var output = new Uint8Array(outputLength);
|
|
1384
|
+
for (var i = 0, j = 0; i < result.length; ++i, j += 16) {
|
|
1385
|
+
output.set(result[Number.parseInt(i.toString(), 10)], j);
|
|
1386
|
+
}
|
|
1387
|
+
return output;
|
|
1388
|
+
};
|
|
1389
|
+
_AdvancedEncryptionBaseCipher.prototype._decryptBlock = function (data, finalize, iv) {
|
|
1390
|
+
var sourceLength = data.length;
|
|
1391
|
+
var buffer = this._buffer;
|
|
1392
|
+
var bufferLength = this._position;
|
|
1393
|
+
if (iv) {
|
|
1394
|
+
this._iv = iv;
|
|
1395
|
+
}
|
|
1396
|
+
else {
|
|
1397
|
+
for (var i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
|
|
1398
|
+
buffer[Number.parseInt(bufferLength.toString(), 10)] = data[Number.parseInt(i.toString(), 10)];
|
|
1399
|
+
}
|
|
1400
|
+
if (bufferLength < 16) {
|
|
1401
|
+
this._bufferLength = bufferLength;
|
|
1402
|
+
return new Uint8Array(0);
|
|
1403
|
+
}
|
|
1404
|
+
this._iv = buffer;
|
|
1405
|
+
data = data.subarray(16);
|
|
1406
|
+
}
|
|
1407
|
+
this._buffer = new Uint8Array(16);
|
|
1408
|
+
this._bufferLength = 0;
|
|
1409
|
+
this._decryptBlock = this._decryptBlockHelper;
|
|
1410
|
+
return this._decryptBlock(data, finalize);
|
|
1411
|
+
};
|
|
1412
|
+
_AdvancedEncryptionBaseCipher.prototype._encrypt = function (data, iv) {
|
|
1413
|
+
var sourceLength = data.length;
|
|
1414
|
+
var buffer = this._buffer;
|
|
1415
|
+
var bufferLength = this._position;
|
|
1416
|
+
var result = [];
|
|
1417
|
+
if (!iv) {
|
|
1418
|
+
iv = new Uint8Array(16);
|
|
1419
|
+
}
|
|
1420
|
+
for (var i = 0; i < sourceLength; ++i) {
|
|
1421
|
+
buffer[Number.parseInt(bufferLength.toString(), 10)] = data[Number.parseInt(i.toString(), 10)];
|
|
1422
|
+
++bufferLength;
|
|
1423
|
+
if (bufferLength < 16) {
|
|
1424
|
+
continue;
|
|
1425
|
+
}
|
|
1426
|
+
for (var j = 0; j < 16; ++j) {
|
|
1427
|
+
buffer[Number.parseInt(j.toString(), 10)] ^= iv[Number.parseInt(j.toString(), 10)];
|
|
1428
|
+
}
|
|
1429
|
+
var cipher = this._encryptBlock(buffer, this._key);
|
|
1430
|
+
iv = cipher;
|
|
1431
|
+
result.push(cipher);
|
|
1432
|
+
buffer = new Uint8Array(16);
|
|
1433
|
+
bufferLength = 0;
|
|
1434
|
+
}
|
|
1435
|
+
this._buffer = buffer;
|
|
1436
|
+
this._bufferLength = bufferLength;
|
|
1437
|
+
this._iv = iv;
|
|
1438
|
+
if (result.length === 0) {
|
|
1439
|
+
return new Uint8Array(0);
|
|
1440
|
+
}
|
|
1441
|
+
var outputLength = 16 * result.length;
|
|
1442
|
+
var output = new Uint8Array(outputLength);
|
|
1443
|
+
for (var i = 0, j = 0; i < result.length; ++i, j += 16) {
|
|
1444
|
+
output.set(result[Number.parseInt(i.toString(), 10)], j);
|
|
1445
|
+
}
|
|
1446
|
+
return output;
|
|
1447
|
+
};
|
|
1448
|
+
return _AdvancedEncryptionBaseCipher;
|
|
1449
|
+
}(_Cipher));
|
|
1450
|
+
export { _AdvancedEncryptionBaseCipher };
|
|
1451
|
+
var _AdvancedEncryption128Cipher = /** @class */ (function (_super) {
|
|
1452
|
+
__extends(_AdvancedEncryption128Cipher, _super);
|
|
1453
|
+
function _AdvancedEncryption128Cipher(key) {
|
|
1454
|
+
var _this = _super.call(this) || this;
|
|
1455
|
+
_this._cyclesOfRepetition = 10;
|
|
1456
|
+
_this._keySize = 160;
|
|
1457
|
+
_this._key = new Uint8Array([
|
|
1458
|
+
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
|
|
1459
|
+
0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
|
|
1460
|
+
0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
|
|
1461
|
+
0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
|
|
1462
|
+
0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
|
|
1463
|
+
0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
|
|
1464
|
+
0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
|
|
1465
|
+
0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
|
|
1466
|
+
0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
|
|
1467
|
+
0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
|
|
1468
|
+
0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
|
|
1469
|
+
0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
|
|
1470
|
+
0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
|
|
1471
|
+
0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
|
|
1472
|
+
0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
|
|
1473
|
+
0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
|
|
1474
|
+
0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
|
|
1475
|
+
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
|
|
1476
|
+
0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
|
|
1477
|
+
0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
|
|
1478
|
+
0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
|
|
1479
|
+
0x74, 0xe8, 0xcb, 0x8d
|
|
1480
|
+
]);
|
|
1481
|
+
_this._key = _this._expandKey(key);
|
|
1482
|
+
return _this;
|
|
1483
|
+
}
|
|
1484
|
+
_AdvancedEncryption128Cipher.prototype._expandKey = function (cipherKey) {
|
|
1485
|
+
var count = 176;
|
|
1486
|
+
var s = this._s;
|
|
1487
|
+
var rcon = this._key;
|
|
1488
|
+
var result = new Uint8Array(count);
|
|
1489
|
+
result.set(cipherKey);
|
|
1490
|
+
for (var j = 16, i = 1; j < count; ++i) {
|
|
1491
|
+
var t1 = result[j - 3];
|
|
1492
|
+
var t2 = result[j - 2];
|
|
1493
|
+
var t3 = result[j - 1];
|
|
1494
|
+
var t4 = result[j - 4];
|
|
1495
|
+
t1 = s[Number.parseInt(t1.toString(), 10)];
|
|
1496
|
+
t2 = s[Number.parseInt(t2.toString(), 10)];
|
|
1497
|
+
t3 = s[Number.parseInt(t3.toString(), 10)];
|
|
1498
|
+
t4 = s[Number.parseInt(t4.toString(), 10)];
|
|
1499
|
+
t1 ^= rcon[Number.parseInt(i.toString(), 10)];
|
|
1500
|
+
for (var n = 0; n < 4; ++n) {
|
|
1501
|
+
result[Number.parseInt(j.toString(), 10)] = t1 ^= result[j - 16];
|
|
1502
|
+
result[j + 1] = t2 ^= result[j - 15];
|
|
1503
|
+
result[j + 2] = t3 ^= result[j - 14];
|
|
1504
|
+
result[j + 3] = t4 ^= result[j - 13];
|
|
1505
|
+
j += 4;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
return result;
|
|
1509
|
+
};
|
|
1510
|
+
return _AdvancedEncryption128Cipher;
|
|
1511
|
+
}(_AdvancedEncryptionBaseCipher));
|
|
1512
|
+
export { _AdvancedEncryption128Cipher };
|
|
1513
|
+
var _AdvancedEncryption256Cipher = /** @class */ (function (_super) {
|
|
1514
|
+
__extends(_AdvancedEncryption256Cipher, _super);
|
|
1515
|
+
function _AdvancedEncryption256Cipher(key) {
|
|
1516
|
+
var _this = _super.call(this) || this;
|
|
1517
|
+
_this._cyclesOfRepetition = 14;
|
|
1518
|
+
_this._keySize = 224;
|
|
1519
|
+
_this._key = _this._expandKey(key);
|
|
1520
|
+
return _this;
|
|
1521
|
+
}
|
|
1522
|
+
_AdvancedEncryption256Cipher.prototype._expandKey = function (cipherKey) {
|
|
1523
|
+
var count = 240;
|
|
1524
|
+
var s = this._s;
|
|
1525
|
+
var result = new Uint8Array(count);
|
|
1526
|
+
result.set(cipherKey);
|
|
1527
|
+
var r = 1;
|
|
1528
|
+
var t1;
|
|
1529
|
+
var t2;
|
|
1530
|
+
var t3;
|
|
1531
|
+
var t4;
|
|
1532
|
+
for (var j = 32, i = 1; j < count; ++i) {
|
|
1533
|
+
if (j % 32 === 16) {
|
|
1534
|
+
t1 = s[Number.parseInt(t1.toString(), 10)];
|
|
1535
|
+
t2 = s[Number.parseInt(t2.toString(), 10)];
|
|
1536
|
+
t3 = s[Number.parseInt(t3.toString(), 10)];
|
|
1537
|
+
t4 = s[Number.parseInt(t4.toString(), 10)];
|
|
1538
|
+
}
|
|
1539
|
+
else if (j % 32 === 0) {
|
|
1540
|
+
t1 = result[j - 3];
|
|
1541
|
+
t2 = result[j - 2];
|
|
1542
|
+
t3 = result[j - 1];
|
|
1543
|
+
t4 = result[j - 4];
|
|
1544
|
+
t1 = s[Number.parseInt(t1.toString(), 10)];
|
|
1545
|
+
t2 = s[Number.parseInt(t2.toString(), 10)];
|
|
1546
|
+
t3 = s[Number.parseInt(t3.toString(), 10)];
|
|
1547
|
+
t4 = s[Number.parseInt(t4.toString(), 10)];
|
|
1548
|
+
t1 ^= r;
|
|
1549
|
+
r = r << 1;
|
|
1550
|
+
if (r >= 256) {
|
|
1551
|
+
r = (r ^ 0x1b) & 0xff;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
for (var n = 0; n < 4; ++n) {
|
|
1555
|
+
result[Number.parseInt(i.toString(), 10)] = t1 ^= result[j - 32];
|
|
1556
|
+
result[j + 1] = t2 ^= result[j - 31];
|
|
1557
|
+
result[j + 2] = t3 ^= result[j - 30];
|
|
1558
|
+
result[j + 3] = t4 ^= result[j - 29];
|
|
1559
|
+
j += 4;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
return result;
|
|
1563
|
+
};
|
|
1564
|
+
return _AdvancedEncryption256Cipher;
|
|
1565
|
+
}(_AdvancedEncryptionBaseCipher));
|
|
1566
|
+
export { _AdvancedEncryption256Cipher };
|
|
1567
|
+
var _NullCipher = /** @class */ (function (_super) {
|
|
1568
|
+
__extends(_NullCipher, _super);
|
|
1569
|
+
function _NullCipher() {
|
|
1570
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1571
|
+
}
|
|
1572
|
+
_NullCipher.prototype._decryptBlock = function (data) {
|
|
1573
|
+
return data;
|
|
1574
|
+
};
|
|
1575
|
+
_NullCipher.prototype._encrypt = function (data) {
|
|
1576
|
+
return data;
|
|
1577
|
+
};
|
|
1578
|
+
return _NullCipher;
|
|
1579
|
+
}(_Cipher));
|
|
1580
|
+
export { _NullCipher };
|
|
1581
|
+
var _CipherTransform = /** @class */ (function () {
|
|
1582
|
+
function _CipherTransform(stringCipher, streamCipher) {
|
|
1583
|
+
this._stringCipher = stringCipher;
|
|
1584
|
+
this._streamCipher = streamCipher;
|
|
1585
|
+
}
|
|
1586
|
+
_CipherTransform.prototype.createStream = function (stream, length) {
|
|
1587
|
+
return new _PdfDecryptStream(stream, length, this._streamCipher);
|
|
1588
|
+
};
|
|
1589
|
+
_CipherTransform.prototype.decryptString = function (s) {
|
|
1590
|
+
return _bytesToString(this._stringCipher._decryptBlock(_stringToBytes(s), true));
|
|
1591
|
+
};
|
|
1592
|
+
_CipherTransform.prototype.encryptString = function (s) {
|
|
1593
|
+
if (this._stringCipher instanceof _AdvancedEncryptionBaseCipher) {
|
|
1594
|
+
var length_2 = s.length;
|
|
1595
|
+
var pad = 16 - (length_2 % 16);
|
|
1596
|
+
s += String.fromCharCode(pad).repeat(pad);
|
|
1597
|
+
var iv = new Uint8Array(16);
|
|
1598
|
+
if (typeof crypto !== 'undefined') {
|
|
1599
|
+
crypto.getRandomValues(iv);
|
|
1600
|
+
}
|
|
1601
|
+
else {
|
|
1602
|
+
for (var i = 0; i < 16; i++) {
|
|
1603
|
+
iv[Number.parseInt(i.toString(), 10)] = Math.floor(256 * Math.random());
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
var data = this._stringCipher._encrypt(_stringToBytes(s), iv);
|
|
1607
|
+
var buffer = new Uint8Array(16 + data.length);
|
|
1608
|
+
buffer.set(iv);
|
|
1609
|
+
buffer.set(data, 16);
|
|
1610
|
+
return _bytesToString(buffer);
|
|
1611
|
+
}
|
|
1612
|
+
return _bytesToString(this._stringCipher._encrypt(_stringToBytes(s)));
|
|
1613
|
+
};
|
|
1614
|
+
return _CipherTransform;
|
|
1615
|
+
}());
|
|
1616
|
+
export { _CipherTransform };
|