| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119 | 1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
| define(["require", "exports", "./pdf-object-identifiers", "../../encryptors/secureHash-algorithm256", "../../encryptors/secureHash-algorithm1", "../../encryptors/secureHash-algorithm512", "../../encryptors/evaluation-digest"], function (require, exports, pdf_object_identifiers_1, secureHash_algorithm256_1, secureHash_algorithm1_1, secureHash_algorithm512_1, evaluation_digest_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _PdfMessageDigestAlgorithms = (function () {
function _PdfMessageDigestAlgorithms() {
this._secureHash1 = 'SHA-1';
this._secureHash256 = 'SHA-256';
this._secureHash384 = 'SHA-384';
this._secureHash512 = 'SHA-512';
this._names = new Map();
this._digests = new Map();
this._algorithms = new Map();
this._initializeNameMappings();
this._initializeDigestMappings();
this._initializeAlgorithmMappings();
}
_PdfMessageDigestAlgorithms.prototype._initializeNameMappings = function () {
this._names.set('1.2.840.113549.2.5', 'MD5');
this._names.set('1.3.14.3.2.26', 'SHA1');
this._names.set('2.16.840.1.101.3.4.2.1', 'SHA256');
this._names.set('2.16.840.1.101.3.4.2.2', 'SHA384');
this._names.set('2.16.840.1.101.3.4.2.3', 'SHA512');
this._names.set('1.3.36.3.2.1', 'RIPEMD160');
this._names.set('1.2.840.113549.1.1.4', 'MD5');
this._names.set('1.2.840.113549.1.1.5', 'SHA1');
this._names.set('1.2.840.113549.1.1.11', 'SHA256');
this._names.set('1.2.840.113549.1.1.12', 'SHA384');
this._names.set('1.2.840.113549.1.1.13', 'SHA512');
this._names.set('1.2.840.10040.4.3', 'SHA1');
this._names.set('2.16.840.1.101.3.4.3.2', 'SHA256');
this._names.set('2.16.840.1.101.3.4.3.3', 'SHA384');
this._names.set('2.16.840.1.101.3.4.3.4', 'SHA512');
this._names.set('1.3.36.3.3.1.2', 'RIPEMD160');
};
_PdfMessageDigestAlgorithms.prototype._initializeDigestMappings = function () {
this._digests.set('MD5', '1.2.840.113549.2.5');
this._digests.set('MD-5', '1.2.840.113549.2.5');
this._digests.set('SHA1', '1.3.14.3.2.26');
this._digests.set('SHA-1', '1.3.14.3.2.26');
this._digests.set('SHA256', '2.16.840.1.101.3.4.2.1');
this._digests.set('SHA-256', '2.16.840.1.101.3.4.2.1');
this._digests.set('SHA384', '2.16.840.1.101.3.4.2.2');
this._digests.set('SHA-384', '2.16.840.1.101.3.4.2.2');
this._digests.set('SHA512', '2.16.840.1.101.3.4.2.3');
this._digests.set('SHA-512', '2.16.840.1.101.3.4.2.3');
this._digests.set('RIPEMD160', '1.3.36.3.2.1');
this._digests.set('RIPEMD-160', '1.3.36.3.2.1');
};
_PdfMessageDigestAlgorithms.prototype._initializeAlgorithmMappings = function () {
var identifiers = new pdf_object_identifiers_1._NistObjectIdentifiers();
var algorithmIdentifiers = new pdf_object_identifiers_1._PdfCryptographicObjectIdentifier();
this._algorithms.set('SHA1', 'SHA-1');
this._algorithms.set('1.3.14.3.2.26', 'SHA-1');
this._algorithms.set('SHA256', 'SHA-256');
this._algorithms.set(identifiers._secureHash256AlgorithmIdentifier.id, 'SHA-256');
this._algorithms.set('SHA384', 'SHA-384');
this._algorithms.set(identifiers._secureHash384AlgorithmIdentifier.id, 'SHA-384');
this._algorithms.set('SHA512', 'SHA-512');
this._algorithms.set(identifiers._secureHash512AlgorithmIdentifier.id, 'SHA-512');
this._algorithms.set('MD5', 'MD5');
this._algorithms.set(algorithmIdentifiers._messageDigest5.id, 'MD5');
this._algorithms.set('RIPEMD-160', 'RIPEMD160');
this._algorithms.set('RIPEMD160', 'RIPEMD160');
this._algorithms.set(identifiers._raceEvaluationMessageDigestAlgorithmIdentifier.id, 'RIPEMD160');
};
_PdfMessageDigestAlgorithms.prototype._getDigest = function (id) {
if (!id) {
return null;
}
return this._names.get(id) || id;
};
_PdfMessageDigestAlgorithms.prototype._getAllowedDigests = function (name) {
var lower = name.toLowerCase();
var result;
this._digests.forEach(function (value, key) {
if ((typeof result === 'undefined' || result === null) && lower === key.toLowerCase()) {
result = value;
}
});
return result;
};
_PdfMessageDigestAlgorithms.prototype._getMessageDigest = function (hashAlgorithm) {
var lower = hashAlgorithm.toLowerCase();
var digest = lower;
var found = false;
this._algorithms.forEach(function (value, key) {
if (!found && key && key.toLowerCase() === lower) {
digest = value;
found = true;
}
});
var normalizedDigest = digest.toLowerCase();
if (normalizedDigest === 'sha1' || normalizedDigest === 'sha-1' || normalizedDigest === 'sha_1') {
return new secureHash_algorithm1_1._Sha1();
}
else if (normalizedDigest === 'sha256' || normalizedDigest === 'sha-256' || normalizedDigest === 'sha_256') {
return new secureHash_algorithm256_1._Sha256();
}
else if (normalizedDigest === 'sha384' || normalizedDigest === 'sha-384' || normalizedDigest === 'sha_384') {
return new secureHash_algorithm512_1._Sha384();
}
else if (normalizedDigest === 'sha512' || normalizedDigest === 'sha-512' || normalizedDigest === 'sha_512') {
return new secureHash_algorithm512_1._Sha512();
}
else if (normalizedDigest === 'ripemd160' || normalizedDigest === 'ripemd-160' || normalizedDigest === 'ripemd_160') {
return new evaluation_digest_1._RaceEvaluationMessageDigest();
}
else {
throw new Error("Invalid message digest algorithm: " + hashAlgorithm);
}
};
_PdfMessageDigestAlgorithms.prototype._digest = function (data, hashAlgorithm) {
return this._getMessageDigest(hashAlgorithm)._hash(data, 0, data.length);
};
return _PdfMessageDigestAlgorithms;
}());
exports._PdfMessageDigestAlgorithms = _PdfMessageDigestAlgorithms;
});
|