react-native-quick-crypto 0.7.0 → 0.7.2
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/README.md +11 -63
- package/android/CMakeLists.txt +2 -0
- package/cpp/Cipher/MGLRsa.cpp +179 -3
- package/cpp/Cipher/MGLRsa.h +40 -0
- package/cpp/JSIUtils/MGLJSIUtils.h +8 -0
- package/cpp/MGLKeys.cpp +41 -43
- package/cpp/MGLKeys.h +9 -2
- package/cpp/MGLQuickCryptoHostObject.cpp +6 -6
- package/cpp/Sig/MGLSignHostObjects.cpp +22 -15
- package/cpp/Utils/MGLUtils.cpp +71 -1
- package/cpp/Utils/MGLUtils.h +55 -1
- package/cpp/webcrypto/MGLWebCrypto.cpp +89 -37
- package/cpp/webcrypto/MGLWebCrypto.h +5 -7
- package/cpp/webcrypto/crypto_aes.cpp +516 -0
- package/cpp/webcrypto/crypto_aes.h +79 -0
- package/cpp/webcrypto/crypto_ec.cpp +4 -20
- package/cpp/webcrypto/crypto_ec.h +0 -5
- package/cpp/webcrypto/crypto_keygen.cpp +86 -0
- package/cpp/webcrypto/crypto_keygen.h +38 -0
- package/lib/commonjs/Cipher.js +3 -1
- package/lib/commonjs/Cipher.js.map +1 -1
- package/lib/commonjs/Hashnames.js +20 -8
- package/lib/commonjs/Hashnames.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +13 -1
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
- package/lib/commonjs/NativeQuickCrypto/aes.js +6 -0
- package/lib/commonjs/NativeQuickCrypto/aes.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/keygen.js +6 -0
- package/lib/commonjs/NativeQuickCrypto/keygen.js.map +1 -0
- package/lib/commonjs/NativeQuickCrypto/rsa.js +6 -0
- package/lib/commonjs/NativeQuickCrypto/rsa.js.map +1 -0
- package/lib/commonjs/Utils.js +30 -6
- package/lib/commonjs/Utils.js.map +1 -1
- package/lib/commonjs/aes.js +184 -227
- package/lib/commonjs/aes.js.map +1 -1
- package/lib/commonjs/index.js +12 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keygen.js +56 -0
- package/lib/commonjs/keygen.js.map +1 -0
- package/lib/commonjs/keys.js +74 -5
- package/lib/commonjs/keys.js.map +1 -1
- package/lib/commonjs/rsa.js +115 -196
- package/lib/commonjs/rsa.js.map +1 -1
- package/lib/commonjs/sig.js.map +1 -1
- package/lib/commonjs/subtle.js +140 -78
- package/lib/commonjs/subtle.js.map +1 -1
- package/lib/commonjs/webcrypto.js +14 -0
- package/lib/commonjs/webcrypto.js.map +1 -0
- package/lib/module/Cipher.js +3 -1
- package/lib/module/Cipher.js.map +1 -1
- package/lib/module/Hashnames.js +20 -8
- package/lib/module/Hashnames.js.map +1 -1
- package/lib/module/NativeQuickCrypto/Cipher.js +12 -0
- package/lib/module/NativeQuickCrypto/Cipher.js.map +1 -1
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +1 -1
- package/lib/module/NativeQuickCrypto/aes.js +2 -0
- package/lib/module/NativeQuickCrypto/aes.js.map +1 -0
- package/lib/module/NativeQuickCrypto/keygen.js +2 -0
- package/lib/module/NativeQuickCrypto/keygen.js.map +1 -0
- package/lib/module/NativeQuickCrypto/rsa.js +2 -0
- package/lib/module/NativeQuickCrypto/rsa.js.map +1 -0
- package/lib/module/Utils.js +26 -5
- package/lib/module/Utils.js.map +1 -1
- package/lib/module/aes.js +183 -228
- package/lib/module/aes.js.map +1 -1
- package/lib/module/index.js +11 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/keygen.js +47 -0
- package/lib/module/keygen.js.map +1 -0
- package/lib/module/keys.js +68 -4
- package/lib/module/keys.js.map +1 -1
- package/lib/module/rsa.js +115 -198
- package/lib/module/rsa.js.map +1 -1
- package/lib/module/sig.js.map +1 -1
- package/lib/module/subtle.js +143 -82
- package/lib/module/subtle.js.map +1 -1
- package/lib/module/webcrypto.js +8 -0
- package/lib/module/webcrypto.js.map +1 -0
- package/lib/typescript/Cipher.d.ts +0 -1
- package/lib/typescript/Cipher.d.ts.map +1 -1
- package/lib/typescript/Hash.d.ts.map +1 -1
- package/lib/typescript/Hashnames.d.ts +2 -2
- package/lib/typescript/Hashnames.d.ts.map +1 -1
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +5 -0
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +1 -1
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +4 -1
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +1 -1
- package/lib/typescript/NativeQuickCrypto/aes.d.ts +5 -0
- package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +1 -0
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts +4 -0
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +1 -0
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts +5 -0
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +1 -0
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +12 -2
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +1 -1
- package/lib/typescript/Utils.d.ts +4 -4
- package/lib/typescript/Utils.d.ts.map +1 -1
- package/lib/typescript/aes.d.ts +18 -1
- package/lib/typescript/aes.d.ts.map +1 -1
- package/lib/typescript/ec.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +27 -24
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keygen.d.ts +6 -0
- package/lib/typescript/keygen.d.ts.map +1 -0
- package/lib/typescript/keys.d.ts +58 -17
- package/lib/typescript/keys.d.ts.map +1 -1
- package/lib/typescript/rsa.d.ts +9 -1
- package/lib/typescript/rsa.d.ts.map +1 -1
- package/lib/typescript/sig.d.ts +3 -17
- package/lib/typescript/sig.d.ts.map +1 -1
- package/lib/typescript/subtle.d.ts +6 -5
- package/lib/typescript/subtle.d.ts.map +1 -1
- package/lib/typescript/webcrypto.d.ts +9 -0
- package/lib/typescript/webcrypto.d.ts.map +1 -0
- package/package.json +12 -12
- package/src/Cipher.ts +1 -1
- package/src/Hashnames.ts +23 -21
- package/src/NativeQuickCrypto/Cipher.ts +32 -0
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +6 -0
- package/src/NativeQuickCrypto/aes.ts +14 -0
- package/src/NativeQuickCrypto/keygen.ts +7 -0
- package/src/NativeQuickCrypto/rsa.ts +12 -0
- package/src/NativeQuickCrypto/webcrypto.ts +26 -2
- package/src/Utils.ts +37 -8
- package/src/aes.ts +259 -222
- package/src/index.ts +10 -1
- package/src/keygen.ts +80 -0
- package/src/keys.ts +143 -30
- package/src/rsa.ts +161 -187
- package/src/sig.ts +7 -23
- package/src/subtle.ts +211 -93
- package/src/webcrypto.ts +8 -0
package/src/rsa.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { KeyVariantLookup } from './NativeQuickCrypto/Cipher';
|
|
2
|
+
import { generateKeyPairPromise } from './Cipher';
|
|
3
3
|
import { NativeQuickCrypto } from './NativeQuickCrypto/NativeQuickCrypto';
|
|
4
|
+
import type { KeyObjectHandle } from './NativeQuickCrypto/webcrypto';
|
|
4
5
|
import {
|
|
5
6
|
lazyDOMException,
|
|
6
7
|
type BufferLike,
|
|
@@ -8,6 +9,10 @@ import {
|
|
|
8
9
|
normalizeHashName,
|
|
9
10
|
HashContext,
|
|
10
11
|
hasAnyNotIn,
|
|
12
|
+
getUsagesUnion,
|
|
13
|
+
bigIntArrayToUnsignedInt,
|
|
14
|
+
validateMaxBufferLength,
|
|
15
|
+
bufferLikeToArrayBuffer,
|
|
11
16
|
} from './Utils';
|
|
12
17
|
import {
|
|
13
18
|
CryptoKey,
|
|
@@ -20,68 +25,20 @@ import {
|
|
|
20
25
|
PublicKeyObject,
|
|
21
26
|
type AnyAlgorithm,
|
|
22
27
|
KeyType,
|
|
28
|
+
createPublicKey,
|
|
29
|
+
type CryptoKeyPair,
|
|
30
|
+
KWebCryptoKeyFormat,
|
|
31
|
+
CipherOrWrapMode,
|
|
32
|
+
type RsaOaepParams,
|
|
33
|
+
type DigestAlgorithm,
|
|
23
34
|
} from './keys';
|
|
24
35
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// KeyObjectHandle,
|
|
32
|
-
// RSACipherJob,
|
|
33
|
-
// RSAKeyExportJob,
|
|
34
|
-
// SignJob,
|
|
35
|
-
// kCryptoJobAsync,
|
|
36
|
-
// kSignJobModeSign,
|
|
37
|
-
// kSignJobModeVerify,
|
|
38
|
-
// kKeyVariantRSA_SSA_PKCS1_v1_5,
|
|
39
|
-
// kKeyVariantRSA_PSS,
|
|
40
|
-
// kKeyVariantRSA_OAEP,
|
|
41
|
-
// kKeyTypePrivate,
|
|
42
|
-
// kWebCryptoCipherEncrypt,
|
|
43
|
-
// RSA_PKCS1_PSS_PADDING,
|
|
44
|
-
// } = internalBinding('crypto');
|
|
45
|
-
|
|
46
|
-
// const {
|
|
47
|
-
// validateInt32,
|
|
48
|
-
// } = require('internal/validators');
|
|
49
|
-
|
|
50
|
-
// const {
|
|
51
|
-
// bigIntArrayToUnsignedInt,
|
|
52
|
-
// getUsagesUnion,
|
|
53
|
-
// hasAnyNotIn,
|
|
54
|
-
// jobPromise,
|
|
55
|
-
// normalizeHashName,
|
|
56
|
-
// validateKeyOps,
|
|
57
|
-
// validateMaxBufferLength,
|
|
58
|
-
// kHandle,
|
|
59
|
-
// kKeyObject,
|
|
60
|
-
// } = require('internal/crypto/util');
|
|
61
|
-
|
|
62
|
-
// const {
|
|
63
|
-
// lazyDOMException,
|
|
64
|
-
// promisify,
|
|
65
|
-
// } = require('internal/util');
|
|
66
|
-
|
|
67
|
-
// const {
|
|
68
|
-
// InternalCryptoKey,
|
|
69
|
-
// PrivateKeyObject,
|
|
70
|
-
// PublicKeyObject,
|
|
71
|
-
// createPublicKey,
|
|
72
|
-
// createPrivateKey,
|
|
73
|
-
// } = require('internal/crypto/keys');
|
|
74
|
-
|
|
75
|
-
// const {
|
|
76
|
-
// generateKeyPair: _generateKeyPair,
|
|
77
|
-
// } = require('internal/crypto/keygen');
|
|
78
|
-
|
|
79
|
-
// const kRsaVariants = {
|
|
80
|
-
// 'RSASSA-PKCS1-v1_5': kKeyVariantRSA_SSA_PKCS1_v1_5,
|
|
81
|
-
// 'RSA-PSS': kKeyVariantRSA_PSS,
|
|
82
|
-
// 'RSA-OAEP': kKeyVariantRSA_OAEP,
|
|
83
|
-
// };
|
|
84
|
-
// const generateKeyPair = promisify(_generateKeyPair);
|
|
36
|
+
// TODO: keep in in sync with C++ side (cpp/Cipher/MGLRsa.h)
|
|
37
|
+
export enum RSAKeyVariant {
|
|
38
|
+
RSA_SSA_PKCS1_v1_5,
|
|
39
|
+
RSA_PSS,
|
|
40
|
+
RSA_OAEP,
|
|
41
|
+
}
|
|
85
42
|
|
|
86
43
|
function verifyAcceptableRsaKeyUse(
|
|
87
44
|
name: AnyAlgorithm,
|
|
@@ -112,120 +69,137 @@ function verifyAcceptableRsaKeyUse(
|
|
|
112
69
|
}
|
|
113
70
|
}
|
|
114
71
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
72
|
+
const rsaOaepCipher = (
|
|
73
|
+
mode: CipherOrWrapMode,
|
|
74
|
+
key: CryptoKey,
|
|
75
|
+
data: ArrayBuffer,
|
|
76
|
+
{ label }: RsaOaepParams
|
|
77
|
+
): Promise<ArrayBuffer> => {
|
|
78
|
+
const type =
|
|
79
|
+
mode === CipherOrWrapMode.kWebCryptoCipherEncrypt ? 'public' : 'private';
|
|
80
|
+
if (key.type !== type) {
|
|
81
|
+
throw lazyDOMException(
|
|
82
|
+
'The requested operation is not valid for the provided key',
|
|
83
|
+
'InvalidAccessError'
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
if (label !== undefined) {
|
|
87
|
+
validateMaxBufferLength(label, 'algorithm.label');
|
|
88
|
+
}
|
|
125
89
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
90
|
+
return NativeQuickCrypto.webcrypto.rsaCipher(
|
|
91
|
+
mode,
|
|
92
|
+
key.keyObject.handle,
|
|
93
|
+
data,
|
|
94
|
+
RSAKeyVariant.RSA_OAEP,
|
|
95
|
+
normalizeHashName(key.algorithm.hash) as DigestAlgorithm,
|
|
96
|
+
label !== undefined ? bufferLikeToArrayBuffer(label) : undefined
|
|
97
|
+
);
|
|
98
|
+
};
|
|
135
99
|
|
|
136
|
-
|
|
137
|
-
// algorithm,
|
|
138
|
-
// extractable,
|
|
139
|
-
// keyUsages) {
|
|
140
|
-
|
|
141
|
-
// const {
|
|
142
|
-
// name,
|
|
143
|
-
// modulusLength,
|
|
144
|
-
// publicExponent,
|
|
145
|
-
// hash,
|
|
146
|
-
// } = algorithm;
|
|
147
|
-
|
|
148
|
-
// const usageSet = new SafeSet(keyUsages);
|
|
149
|
-
|
|
150
|
-
// const publicExponentConverted = bigIntArrayToUnsignedInt(publicExponent);
|
|
151
|
-
// if (publicExponentConverted === undefined) {
|
|
152
|
-
// throw lazyDOMException(
|
|
153
|
-
// 'The publicExponent must be equivalent to an unsigned 32-bit value',
|
|
154
|
-
// 'OperationError');
|
|
155
|
-
// }
|
|
100
|
+
export const rsaCipher = rsaOaepCipher;
|
|
156
101
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
// }
|
|
165
|
-
// break;
|
|
166
|
-
// default:
|
|
167
|
-
// if (hasAnyNotIn(usageSet, ['sign', 'verify'])) {
|
|
168
|
-
// throw lazyDOMException(
|
|
169
|
-
// 'Unsupported key usage for a RSA key',
|
|
170
|
-
// 'SyntaxError');
|
|
171
|
-
// }
|
|
172
|
-
// }
|
|
102
|
+
export const rsaKeyGenerate = async (
|
|
103
|
+
algorithm: SubtleAlgorithm,
|
|
104
|
+
extractable: boolean,
|
|
105
|
+
keyUsages: KeyUsage[]
|
|
106
|
+
): Promise<CryptoKeyPair> => {
|
|
107
|
+
const { name, modulusLength, publicExponent, hash: rawHash } = algorithm;
|
|
108
|
+
const hash: HashAlgorithm = normalizeHashName(rawHash);
|
|
173
109
|
|
|
174
|
-
//
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
// const keyAlgorithm = {
|
|
184
|
-
// name,
|
|
185
|
-
// modulusLength,
|
|
186
|
-
// publicExponent,
|
|
187
|
-
// hash: { name: hash.name },
|
|
188
|
-
// };
|
|
189
|
-
|
|
190
|
-
// let publicUsages;
|
|
191
|
-
// let privateUsages;
|
|
192
|
-
// switch (name) {
|
|
193
|
-
// case 'RSA-OAEP': {
|
|
194
|
-
// publicUsages = getUsagesUnion(usageSet, 'encrypt', 'wrapKey');
|
|
195
|
-
// privateUsages = getUsagesUnion(usageSet, 'decrypt', 'unwrapKey');
|
|
196
|
-
// break;
|
|
197
|
-
// }
|
|
198
|
-
// default: {
|
|
199
|
-
// publicUsages = getUsagesUnion(usageSet, 'verify');
|
|
200
|
-
// privateUsages = getUsagesUnion(usageSet, 'sign');
|
|
201
|
-
// break;
|
|
202
|
-
// }
|
|
203
|
-
// }
|
|
110
|
+
// const usageSet = new SafeSet(keyUsages);
|
|
111
|
+
const publicExponentConverted = bigIntArrayToUnsignedInt(publicExponent);
|
|
112
|
+
if (publicExponentConverted === undefined) {
|
|
113
|
+
throw lazyDOMException(
|
|
114
|
+
'The publicExponent must be equivalent to an unsigned 32-bit value',
|
|
115
|
+
'OperationError'
|
|
116
|
+
);
|
|
117
|
+
}
|
|
204
118
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
119
|
+
switch (name) {
|
|
120
|
+
case 'RSA-OAEP':
|
|
121
|
+
if (
|
|
122
|
+
hasAnyNotIn(keyUsages, ['encrypt', 'decrypt', 'wrapKey', 'unwrapKey'])
|
|
123
|
+
) {
|
|
124
|
+
throw lazyDOMException(
|
|
125
|
+
'Unsupported key usage for a RSA key',
|
|
126
|
+
'SyntaxError'
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
default:
|
|
131
|
+
if (hasAnyNotIn(keyUsages, ['sign', 'verify'])) {
|
|
132
|
+
throw lazyDOMException(
|
|
133
|
+
'Unsupported key usage for a RSA key',
|
|
134
|
+
'SyntaxError'
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
221
138
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
139
|
+
const [err, keypair] = await generateKeyPairPromise('rsa', {
|
|
140
|
+
modulusLength,
|
|
141
|
+
publicExponent: publicExponentConverted,
|
|
142
|
+
});
|
|
143
|
+
if (err) {
|
|
144
|
+
throw lazyDOMException(
|
|
145
|
+
'The operation failed for an operation-specific reason',
|
|
146
|
+
{ name: 'OperationError', cause: err }
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const keyAlgorithm = {
|
|
151
|
+
name,
|
|
152
|
+
modulusLength,
|
|
153
|
+
publicExponent: publicExponentConverted,
|
|
154
|
+
hash,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
let publicUsages: KeyUsage[] = [];
|
|
158
|
+
let privateUsages: KeyUsage[] = [];
|
|
159
|
+
switch (name) {
|
|
160
|
+
case 'RSA-OAEP': {
|
|
161
|
+
publicUsages = getUsagesUnion(keyUsages, 'encrypt', 'wrapKey');
|
|
162
|
+
privateUsages = getUsagesUnion(keyUsages, 'decrypt', 'unwrapKey');
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
default: {
|
|
166
|
+
publicUsages = getUsagesUnion(keyUsages, 'verify');
|
|
167
|
+
privateUsages = getUsagesUnion(keyUsages, 'sign');
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const pub = new PublicKeyObject(keypair?.publicKey as KeyObjectHandle);
|
|
173
|
+
const publicKey = new CryptoKey(pub, keyAlgorithm, publicUsages, true);
|
|
174
|
+
|
|
175
|
+
const priv = new PrivateKeyObject(keypair?.privateKey as KeyObjectHandle);
|
|
176
|
+
const privateKey = new CryptoKey(
|
|
177
|
+
priv,
|
|
178
|
+
keyAlgorithm,
|
|
179
|
+
privateUsages,
|
|
180
|
+
extractable
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
return { publicKey, privateKey };
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const rsaExportKey = (
|
|
187
|
+
key: CryptoKey,
|
|
188
|
+
format: KWebCryptoKeyFormat
|
|
189
|
+
): ArrayBuffer => {
|
|
190
|
+
const variant = KeyVariantLookup[key.algorithm.name];
|
|
191
|
+
if (variant === undefined) {
|
|
192
|
+
throw lazyDOMException(
|
|
193
|
+
`Unrecognized algorithm name '${key.algorithm.name}'`,
|
|
194
|
+
'NotSupportedError'
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
return NativeQuickCrypto.webcrypto.rsaExportKey(
|
|
198
|
+
format,
|
|
199
|
+
key.keyObject.handle,
|
|
200
|
+
variant
|
|
201
|
+
);
|
|
202
|
+
};
|
|
229
203
|
|
|
230
204
|
export const rsaImportKey = (
|
|
231
205
|
format: ImportFormat,
|
|
@@ -235,24 +209,24 @@ export const rsaImportKey = (
|
|
|
235
209
|
keyUsages: KeyUsage[]
|
|
236
210
|
): CryptoKey => {
|
|
237
211
|
// const usagesSet = new SafeSet(keyUsages);
|
|
238
|
-
let keyObject;
|
|
212
|
+
let keyObject: PublicKeyObject | PrivateKeyObject;
|
|
239
213
|
switch (format) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
214
|
+
case 'spki': {
|
|
215
|
+
verifyAcceptableRsaKeyUse(algorithm.name, true, keyUsages);
|
|
216
|
+
try {
|
|
217
|
+
keyObject = createPublicKey({
|
|
218
|
+
key: keyData,
|
|
219
|
+
format: 'der',
|
|
220
|
+
type: 'spki',
|
|
221
|
+
});
|
|
222
|
+
} catch (err) {
|
|
223
|
+
throw lazyDOMException('Invalid keyData', {
|
|
224
|
+
name: 'DataError',
|
|
225
|
+
cause: err,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
256
230
|
// case 'pkcs8': {
|
|
257
231
|
// verifyAcceptableRsaKeyUse(algorithm.name, false, keyUsages);
|
|
258
232
|
// try {
|
package/src/sig.ts
CHANGED
|
@@ -14,7 +14,11 @@ import {
|
|
|
14
14
|
binaryLikeToArrayBuffer,
|
|
15
15
|
getDefaultEncoding,
|
|
16
16
|
} from './Utils';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
preparePrivateKey,
|
|
19
|
+
preparePublicOrPrivateKey,
|
|
20
|
+
type EncodingOptions,
|
|
21
|
+
} from './keys';
|
|
18
22
|
|
|
19
23
|
const createInternalSign = NativeQuickCrypto.createSign;
|
|
20
24
|
const createInternalVerify = NativeQuickCrypto.createVerify;
|
|
@@ -70,17 +74,7 @@ class Verify extends Stream.Writable {
|
|
|
70
74
|
return this;
|
|
71
75
|
}
|
|
72
76
|
|
|
73
|
-
verify(
|
|
74
|
-
options: {
|
|
75
|
-
key: string | Buffer;
|
|
76
|
-
format?: string;
|
|
77
|
-
type?: string;
|
|
78
|
-
passphrase?: string;
|
|
79
|
-
padding?: number;
|
|
80
|
-
saltLength?: number;
|
|
81
|
-
},
|
|
82
|
-
signature: BinaryLike
|
|
83
|
-
): boolean {
|
|
77
|
+
verify(options: EncodingOptions, signature: BinaryLike): boolean {
|
|
84
78
|
if (!options) {
|
|
85
79
|
throw new Error('Crypto sign key required');
|
|
86
80
|
}
|
|
@@ -129,17 +123,7 @@ class Sign extends Stream.Writable {
|
|
|
129
123
|
return this;
|
|
130
124
|
}
|
|
131
125
|
|
|
132
|
-
sign(
|
|
133
|
-
options: {
|
|
134
|
-
key: string | Buffer;
|
|
135
|
-
format?: string;
|
|
136
|
-
type?: string;
|
|
137
|
-
passphrase?: string;
|
|
138
|
-
padding?: number;
|
|
139
|
-
saltLength?: number;
|
|
140
|
-
},
|
|
141
|
-
encoding?: string
|
|
142
|
-
) {
|
|
126
|
+
sign(options: EncodingOptions, encoding?: string) {
|
|
143
127
|
if (!options) {
|
|
144
128
|
throw new Error('Crypto sign key required');
|
|
145
129
|
}
|