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/subtle.ts
CHANGED
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
type AnyAlgorithm,
|
|
9
9
|
type JWK,
|
|
10
10
|
type CryptoKeyPair,
|
|
11
|
+
CipherOrWrapMode,
|
|
12
|
+
type EncryptDecryptParams,
|
|
13
|
+
type AesKeyGenParams,
|
|
11
14
|
} from './keys';
|
|
12
15
|
import {
|
|
13
16
|
hasAnyNotIn,
|
|
@@ -18,32 +21,72 @@ import {
|
|
|
18
21
|
normalizeHashName,
|
|
19
22
|
HashContext,
|
|
20
23
|
type Operation,
|
|
24
|
+
validateMaxBufferLength,
|
|
25
|
+
bufferLikeToArrayBuffer,
|
|
21
26
|
} from './Utils';
|
|
22
27
|
import { ecImportKey, ecExportKey, ecGenerateKey, ecdsaSignVerify } from './ec';
|
|
23
28
|
import { pbkdf2DeriveBits } from './pbkdf2';
|
|
24
29
|
import { asyncDigest } from './Hash';
|
|
25
|
-
import {
|
|
26
|
-
|
|
30
|
+
import {
|
|
31
|
+
aesCipher,
|
|
32
|
+
aesGenerateKey,
|
|
33
|
+
aesImportKey,
|
|
34
|
+
getAlgorithmName,
|
|
35
|
+
} from './aes';
|
|
36
|
+
import { rsaCipher, rsaExportKey, rsaImportKey, rsaKeyGenerate } from './rsa';
|
|
27
37
|
|
|
28
38
|
const exportKeySpki = async (key: CryptoKey): Promise<ArrayBuffer | any> => {
|
|
29
39
|
switch (key.algorithm.name) {
|
|
30
|
-
|
|
40
|
+
case 'RSASSA-PKCS1-v1_5':
|
|
41
|
+
// Fall through
|
|
42
|
+
case 'RSA-PSS':
|
|
43
|
+
// Fall through
|
|
44
|
+
case 'RSA-OAEP':
|
|
45
|
+
if (key.type === 'public') {
|
|
46
|
+
return rsaExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatSPKI);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
case 'ECDSA':
|
|
50
|
+
// Fall through
|
|
51
|
+
case 'ECDH':
|
|
52
|
+
if (key.type === 'public') {
|
|
53
|
+
return ecExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatSPKI);
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
// case 'Ed25519':
|
|
31
57
|
// // Fall through
|
|
32
|
-
// case '
|
|
58
|
+
// case 'Ed448':
|
|
33
59
|
// // Fall through
|
|
34
|
-
// case '
|
|
60
|
+
// case 'X25519':
|
|
61
|
+
// // Fall through
|
|
62
|
+
// case 'X448':
|
|
35
63
|
// if (key.type === 'public') {
|
|
36
|
-
// return
|
|
37
|
-
// key,
|
|
38
|
-
// kWebCryptoKeyFormatSPKI
|
|
39
|
-
// );
|
|
64
|
+
// return cfrgExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatSPKI);
|
|
40
65
|
// }
|
|
41
66
|
// break;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Unable to export a spki ${key.algorithm.name} ${key.type} key`
|
|
71
|
+
);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const exportKeyPkcs8 = async (key: CryptoKey): Promise<ArrayBuffer | any> => {
|
|
75
|
+
switch (key.algorithm.name) {
|
|
76
|
+
case 'RSASSA-PKCS1-v1_5':
|
|
77
|
+
// Fall through
|
|
78
|
+
case 'RSA-PSS':
|
|
79
|
+
// Fall through
|
|
80
|
+
case 'RSA-OAEP':
|
|
81
|
+
if (key.type === 'private') {
|
|
82
|
+
return rsaExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatPKCS8);
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
42
85
|
case 'ECDSA':
|
|
43
86
|
// Fall through
|
|
44
87
|
case 'ECDH':
|
|
45
|
-
if (key.type === '
|
|
46
|
-
return ecExportKey(key, KWebCryptoKeyFormat.
|
|
88
|
+
if (key.type === 'private') {
|
|
89
|
+
return ecExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatPKCS8);
|
|
47
90
|
}
|
|
48
91
|
break;
|
|
49
92
|
// case 'Ed25519':
|
|
@@ -53,17 +96,14 @@ const exportKeySpki = async (key: CryptoKey): Promise<ArrayBuffer | any> => {
|
|
|
53
96
|
// case 'X25519':
|
|
54
97
|
// // Fall through
|
|
55
98
|
// case 'X448':
|
|
56
|
-
// if (key.type === '
|
|
57
|
-
// return
|
|
58
|
-
// key,
|
|
59
|
-
// kWebCryptoKeyFormatSPKI
|
|
60
|
-
// );
|
|
99
|
+
// if (key.type === 'private') {
|
|
100
|
+
// return cfrgExportKey(key, KWebCryptoKeyFormat.kWebCryptoKeyFormatPKCS8);
|
|
61
101
|
// }
|
|
62
102
|
// break;
|
|
63
103
|
}
|
|
64
104
|
|
|
65
105
|
throw new Error(
|
|
66
|
-
`Unable to export a
|
|
106
|
+
`Unable to export a pkcs8 ${key.algorithm.name} ${key.type} key`
|
|
67
107
|
);
|
|
68
108
|
};
|
|
69
109
|
|
|
@@ -285,7 +325,70 @@ const signVerify = (
|
|
|
285
325
|
);
|
|
286
326
|
};
|
|
287
327
|
|
|
288
|
-
|
|
328
|
+
const cipherOrWrap = async (
|
|
329
|
+
mode: CipherOrWrapMode,
|
|
330
|
+
algorithm: EncryptDecryptParams, // | WrapUnwrapParams,
|
|
331
|
+
key: CryptoKey,
|
|
332
|
+
data: ArrayBuffer,
|
|
333
|
+
op: Operation
|
|
334
|
+
): Promise<ArrayBuffer> => {
|
|
335
|
+
// We use a Node.js style error here instead of a DOMException because
|
|
336
|
+
// the WebCrypto spec is not specific what kind of error is to be thrown
|
|
337
|
+
// in this case. Both Firefox and Chrome throw simple TypeErrors here.
|
|
338
|
+
// The key algorithm and cipher algorithm must match, and the
|
|
339
|
+
// key must have the proper usage.
|
|
340
|
+
if (
|
|
341
|
+
key.algorithm.name !== algorithm.name ||
|
|
342
|
+
!key.usages.includes(op as KeyUsage)
|
|
343
|
+
) {
|
|
344
|
+
throw lazyDOMException(
|
|
345
|
+
'The requested operation is not valid for the provided key',
|
|
346
|
+
'InvalidAccessError'
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// While WebCrypto allows for larger input buffer sizes, we limit
|
|
351
|
+
// those to sizes that can fit within uint32_t because of limitations
|
|
352
|
+
// in the OpenSSL API.
|
|
353
|
+
validateMaxBufferLength(data, 'data');
|
|
354
|
+
|
|
355
|
+
switch (algorithm.name) {
|
|
356
|
+
case 'RSA-OAEP':
|
|
357
|
+
return rsaCipher(mode, key, data, algorithm);
|
|
358
|
+
case 'AES-CTR':
|
|
359
|
+
// Fall through
|
|
360
|
+
case 'AES-CBC':
|
|
361
|
+
// Fall through
|
|
362
|
+
case 'AES-GCM':
|
|
363
|
+
return aesCipher(mode, key, data, algorithm);
|
|
364
|
+
// case 'AES-KW':
|
|
365
|
+
// if (op === 'wrapKey' || op === 'unwrapKey') {
|
|
366
|
+
// return aesCipher(mode, key, data, algorithm);
|
|
367
|
+
// }
|
|
368
|
+
}
|
|
369
|
+
// @ts-ignore
|
|
370
|
+
throw lazyDOMException(
|
|
371
|
+
`Unrecognized algorithm name '${algorithm}' for '${op}'`,
|
|
372
|
+
'NotSupportedError'
|
|
373
|
+
);
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
export class Subtle {
|
|
377
|
+
async decrypt(
|
|
378
|
+
algorithm: EncryptDecryptParams,
|
|
379
|
+
key: CryptoKey,
|
|
380
|
+
data: BufferLike
|
|
381
|
+
): Promise<ArrayBuffer> {
|
|
382
|
+
const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'decrypt');
|
|
383
|
+
return cipherOrWrap(
|
|
384
|
+
CipherOrWrapMode.kWebCryptoCipherDecrypt,
|
|
385
|
+
normalizedAlgorithm as EncryptDecryptParams,
|
|
386
|
+
key,
|
|
387
|
+
bufferLikeToArrayBuffer(data),
|
|
388
|
+
'decrypt'
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
289
392
|
async digest(
|
|
290
393
|
algorithm: SubtleAlgorithm | AnyAlgorithm,
|
|
291
394
|
data: BufferLike
|
|
@@ -323,6 +426,96 @@ class Subtle {
|
|
|
323
426
|
);
|
|
324
427
|
}
|
|
325
428
|
|
|
429
|
+
async encrypt(
|
|
430
|
+
algorithm: EncryptDecryptParams,
|
|
431
|
+
key: CryptoKey,
|
|
432
|
+
data: BufferLike
|
|
433
|
+
): Promise<ArrayBuffer> {
|
|
434
|
+
const normalizedAlgorithm = normalizeAlgorithm(algorithm, 'encrypt');
|
|
435
|
+
return cipherOrWrap(
|
|
436
|
+
CipherOrWrapMode.kWebCryptoCipherEncrypt,
|
|
437
|
+
normalizedAlgorithm as EncryptDecryptParams,
|
|
438
|
+
key,
|
|
439
|
+
bufferLikeToArrayBuffer(data),
|
|
440
|
+
'encrypt'
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
async exportKey(
|
|
445
|
+
format: ImportFormat,
|
|
446
|
+
key: CryptoKey
|
|
447
|
+
): Promise<ArrayBuffer | JWK> {
|
|
448
|
+
if (!key.extractable) throw new Error('key is not extractable');
|
|
449
|
+
|
|
450
|
+
switch (format) {
|
|
451
|
+
case 'spki':
|
|
452
|
+
return await exportKeySpki(key);
|
|
453
|
+
case 'pkcs8':
|
|
454
|
+
return await exportKeyPkcs8(key);
|
|
455
|
+
case 'jwk':
|
|
456
|
+
return exportKeyJWK(key);
|
|
457
|
+
case 'raw':
|
|
458
|
+
return exportKeyRaw(key);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
async generateKey(
|
|
463
|
+
algorithm: SubtleAlgorithm,
|
|
464
|
+
extractable: boolean,
|
|
465
|
+
keyUsages: KeyUsage[]
|
|
466
|
+
): Promise<CryptoKey | CryptoKeyPair> {
|
|
467
|
+
algorithm = normalizeAlgorithm(algorithm, 'generateKey');
|
|
468
|
+
let result: CryptoKey | CryptoKeyPair;
|
|
469
|
+
switch (algorithm.name) {
|
|
470
|
+
case 'RSASSA-PKCS1-v1_5':
|
|
471
|
+
// Fall through
|
|
472
|
+
case 'RSA-PSS':
|
|
473
|
+
// Fall through
|
|
474
|
+
case 'RSA-OAEP':
|
|
475
|
+
result = await rsaKeyGenerate(algorithm, extractable, keyUsages);
|
|
476
|
+
break;
|
|
477
|
+
// case 'Ed25519':
|
|
478
|
+
// // Fall through
|
|
479
|
+
// case 'Ed448':
|
|
480
|
+
// // Fall through
|
|
481
|
+
// case 'X25519':
|
|
482
|
+
// // Fall through
|
|
483
|
+
// case 'X448':
|
|
484
|
+
// resultType = 'CryptoKeyPair';
|
|
485
|
+
// result = await cfrgGenerateKey(algorithm, extractable, keyUsages);
|
|
486
|
+
// break;
|
|
487
|
+
case 'ECDSA':
|
|
488
|
+
// Fall through
|
|
489
|
+
case 'ECDH':
|
|
490
|
+
result = await ecGenerateKey(algorithm, extractable, keyUsages);
|
|
491
|
+
checkCryptoKeyPairUsages(result);
|
|
492
|
+
break;
|
|
493
|
+
// case 'HMAC':
|
|
494
|
+
// result = await hmacGenerateKey(algorithm, extractable, keyUsages);
|
|
495
|
+
// break;
|
|
496
|
+
case 'AES-CTR':
|
|
497
|
+
// Fall through
|
|
498
|
+
case 'AES-CBC':
|
|
499
|
+
// Fall through
|
|
500
|
+
case 'AES-GCM':
|
|
501
|
+
// Fall through
|
|
502
|
+
case 'AES-KW':
|
|
503
|
+
result = await aesGenerateKey(
|
|
504
|
+
algorithm as AesKeyGenParams,
|
|
505
|
+
extractable,
|
|
506
|
+
keyUsages
|
|
507
|
+
);
|
|
508
|
+
break;
|
|
509
|
+
default:
|
|
510
|
+
throw new Error(
|
|
511
|
+
`'subtle.generateKey()' is not implemented for ${algorithm.name}.
|
|
512
|
+
Unrecognized algorithm name`
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return result;
|
|
517
|
+
}
|
|
518
|
+
|
|
326
519
|
async importKey(
|
|
327
520
|
format: ImportFormat,
|
|
328
521
|
data: BufferLike | BinaryLike | JWK,
|
|
@@ -425,81 +618,6 @@ class Subtle {
|
|
|
425
618
|
return result;
|
|
426
619
|
}
|
|
427
620
|
|
|
428
|
-
async exportKey(
|
|
429
|
-
format: ImportFormat,
|
|
430
|
-
key: CryptoKey
|
|
431
|
-
): Promise<ArrayBuffer | any> {
|
|
432
|
-
if (!key.extractable) throw new Error('key is not extractable');
|
|
433
|
-
|
|
434
|
-
switch (format) {
|
|
435
|
-
case 'spki':
|
|
436
|
-
return await exportKeySpki(key);
|
|
437
|
-
// case 'pkcs8':
|
|
438
|
-
// return await exportKeyPkcs8(key);
|
|
439
|
-
case 'jwk':
|
|
440
|
-
return exportKeyJWK(key);
|
|
441
|
-
case 'raw':
|
|
442
|
-
return exportKeyRaw(key);
|
|
443
|
-
}
|
|
444
|
-
throw new Error(`'subtle.exportKey()' is not implemented for ${format}`);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
async generateKey(
|
|
448
|
-
algorithm: SubtleAlgorithm,
|
|
449
|
-
extractable: boolean,
|
|
450
|
-
keyUsages: KeyUsage[]
|
|
451
|
-
): Promise<CryptoKey | CryptoKeyPair> {
|
|
452
|
-
algorithm = normalizeAlgorithm(algorithm, 'generateKey');
|
|
453
|
-
let result: CryptoKey | CryptoKeyPair;
|
|
454
|
-
switch (algorithm.name) {
|
|
455
|
-
// case 'RSASSA-PKCS1-v1_5':
|
|
456
|
-
// // Fall through
|
|
457
|
-
// case 'RSA-PSS':
|
|
458
|
-
// // Fall through
|
|
459
|
-
// case 'RSA-OAEP':
|
|
460
|
-
// resultType = 'CryptoKeyPair';
|
|
461
|
-
// result = await rsaKeyGenerate(algorithm, extractable, keyUsages);
|
|
462
|
-
// break;
|
|
463
|
-
// case 'Ed25519':
|
|
464
|
-
// // Fall through
|
|
465
|
-
// case 'Ed448':
|
|
466
|
-
// // Fall through
|
|
467
|
-
// case 'X25519':
|
|
468
|
-
// // Fall through
|
|
469
|
-
// case 'X448':
|
|
470
|
-
// resultType = 'CryptoKeyPair';
|
|
471
|
-
// result = await cfrgGenerateKey(algorithm, extractable, keyUsages);
|
|
472
|
-
// break;
|
|
473
|
-
case 'ECDSA':
|
|
474
|
-
// Fall through
|
|
475
|
-
case 'ECDH':
|
|
476
|
-
result = await ecGenerateKey(algorithm, extractable, keyUsages);
|
|
477
|
-
checkCryptoKeyPairUsages(result);
|
|
478
|
-
break;
|
|
479
|
-
// case 'HMAC':
|
|
480
|
-
// resultType = 'CryptoKey';
|
|
481
|
-
// result = await hmacGenerateKey(algorithm, extractable, keyUsages);
|
|
482
|
-
// break;
|
|
483
|
-
// case 'AES-CTR':
|
|
484
|
-
// // Fall through
|
|
485
|
-
// case 'AES-CBC':
|
|
486
|
-
// // Fall through
|
|
487
|
-
// case 'AES-GCM':
|
|
488
|
-
// // Fall through
|
|
489
|
-
// case 'AES-KW':
|
|
490
|
-
// resultType = 'CryptoKey';
|
|
491
|
-
// result = await aesGenerateKey(algorithm, extractable, keyUsages);
|
|
492
|
-
// break;
|
|
493
|
-
default:
|
|
494
|
-
throw new Error(
|
|
495
|
-
`'subtle.generateKey()' is not implemented for ${algorithm.name}.
|
|
496
|
-
Unrecognized algorithm name`
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
return result;
|
|
501
|
-
}
|
|
502
|
-
|
|
503
621
|
async sign(
|
|
504
622
|
algorithm: SubtleAlgorithm,
|
|
505
623
|
key: CryptoKey,
|