micro509 0.7.2 → 0.8.0
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/dist/index.d.ts +5 -5
- package/dist/index.js +15 -1
- package/dist/internal/asn1/asn1.js +280 -2
- package/dist/internal/asn1/der.js +378 -2
- package/dist/internal/asn1/oids.js +103 -2
- package/dist/internal/crypto/algorithm-names.js +58 -2
- package/dist/internal/crypto/ecdsa.js +68 -2
- package/dist/internal/crypto/hash.js +286 -2
- package/dist/internal/crypto/pbes2.js +213 -2
- package/dist/internal/crypto/rsa-pss.js +184 -2
- package/dist/internal/crypto/sig-verify.js +192 -2
- package/dist/internal/crypto/signing.d.ts +1 -2
- package/dist/internal/crypto/signing.js +123 -2
- package/dist/internal/crypto/webcrypto.js +14 -2
- package/dist/internal/shared/base64.js +16 -2
- package/dist/internal/shared/dn.js +84 -2
- package/dist/internal/shared/ip.js +164 -2
- package/dist/internal/verify/name-constraints-engine.js +450 -2
- package/dist/internal/verify/policy-engine.js +382 -2
- package/dist/internal/verify/verify-path.js +298 -2
- package/dist/internal/x509/extension-bits.js +132 -2
- package/dist/internal/x509/extension-registry.js +229 -2
- package/dist/internal/x509/name-fields.js +93 -2
- package/dist/keys/keys.d.ts +231 -7
- package/dist/keys/keys.js +1087 -5
- package/dist/keys.d.ts +2 -2
- package/dist/keys.js +2 -1
- package/dist/pem/pem.d.ts +2 -2
- package/dist/pem/pem.js +172 -6
- package/dist/pem.js +2 -1
- package/dist/pkcs/pfx.d.ts +4 -5
- package/dist/pkcs/pfx.js +395 -2
- package/dist/pkcs/pkcs12-mac.d.ts +2 -2
- package/dist/pkcs/pkcs12-mac.js +175 -2
- package/dist/pkcs/pkcs7.d.ts +1 -2
- package/dist/pkcs/pkcs7.js +653 -2
- package/dist/pkcs.d.ts +2 -2
- package/dist/pkcs.js +4 -1
- package/dist/result/result.d.ts +1 -2
- package/dist/result/result.js +111 -2
- package/dist/result.js +2 -1
- package/dist/revocation/chain.d.ts +4 -5
- package/dist/revocation/chain.js +536 -2
- package/dist/revocation/crl.d.ts +2 -2
- package/dist/revocation/crl.js +1119 -2
- package/dist/revocation/ocsp.d.ts +3 -2
- package/dist/revocation/ocsp.js +958 -2
- package/dist/revocation/revocation.d.ts +1 -2
- package/dist/revocation/revocation.js +261 -2
- package/dist/revocation.d.ts +2 -2
- package/dist/revocation.js +5 -1
- package/dist/verify/identity.d.ts +1 -2
- package/dist/verify/identity.js +270 -2
- package/dist/verify/name-constraints.d.ts +1 -2
- package/dist/verify/policy.d.ts +1 -2
- package/dist/verify/verify.d.ts +1 -2
- package/dist/verify/verify.js +764 -2
- package/dist/verify.js +3 -1
- package/dist/x509/certificate.d.ts +1 -2
- package/dist/x509/certificate.js +151 -2
- package/dist/x509/csr.d.ts +1 -2
- package/dist/x509/csr.js +71 -2
- package/dist/x509/extensions.d.ts +1 -2
- package/dist/x509/extensions.js +387 -2
- package/dist/x509/name.d.ts +1 -2
- package/dist/x509/name.js +173 -2
- package/dist/x509/parse.d.ts +84 -2
- package/dist/x509/parse.js +1090 -2
- package/dist/x509.d.ts +2 -2
- package/dist/x509.js +6 -1
- package/package.json +74 -34
- package/dist/internal/asn1/asn1.js.map +0 -1
- package/dist/internal/asn1/der.js.map +0 -1
- package/dist/internal/asn1/oids.js.map +0 -1
- package/dist/internal/crypto/algorithm-names.js.map +0 -1
- package/dist/internal/crypto/ecdsa.js.map +0 -1
- package/dist/internal/crypto/hash.js.map +0 -1
- package/dist/internal/crypto/pbes2.d.ts +0 -23
- package/dist/internal/crypto/pbes2.js.map +0 -1
- package/dist/internal/crypto/rsa-pss.js.map +0 -1
- package/dist/internal/crypto/sig-verify.js.map +0 -1
- package/dist/internal/crypto/signing.js.map +0 -1
- package/dist/internal/crypto/webcrypto.js.map +0 -1
- package/dist/internal/shared/base64.js.map +0 -1
- package/dist/internal/shared/dn.js.map +0 -1
- package/dist/internal/shared/ip.js.map +0 -1
- package/dist/internal/verify/name-constraints-engine.js.map +0 -1
- package/dist/internal/verify/policy-engine.js.map +0 -1
- package/dist/internal/verify/verify-path.js.map +0 -1
- package/dist/internal/x509/extension-bits.js.map +0 -1
- package/dist/internal/x509/extension-registry.js.map +0 -1
- package/dist/internal/x509/name-fields.js.map +0 -1
- package/dist/keys/keys.js.map +0 -1
- package/dist/pem/pem.js.map +0 -1
- package/dist/pkcs/pfx.js.map +0 -1
- package/dist/pkcs/pkcs12-mac.js.map +0 -1
- package/dist/pkcs/pkcs7.js.map +0 -1
- package/dist/result/result.js.map +0 -1
- package/dist/revocation/chain.js.map +0 -1
- package/dist/revocation/crl.js.map +0 -1
- package/dist/revocation/ocsp.js.map +0 -1
- package/dist/revocation/revocation.js.map +0 -1
- package/dist/verify/identity.js.map +0 -1
- package/dist/verify/verify.js.map +0 -1
- package/dist/x509/certificate.js.map +0 -1
- package/dist/x509/csr.js.map +0 -1
- package/dist/x509/extensions.js.map +0 -1
- package/dist/x509/name.js.map +0 -1
- package/dist/x509/parse.js.map +0 -1
package/dist/keys/keys.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Pbes2EncryptionOptions, Pbes2EncryptionScheme, Pbes2Prf } from "../internal/crypto/pbes2.js";
|
|
2
1
|
import { ErrorResult, Micro509Error } from "../result/result.js";
|
|
3
2
|
|
|
4
3
|
//#region src/keys/keys.d.ts
|
|
@@ -78,7 +77,20 @@ type PublicKeyImportInput = ImportRsaKeyInput | ImportEcKeyInput | ImportEd25519
|
|
|
78
77
|
/** Algorithm descriptor for private key import functions. Same shape as {@linkcode PublicKeyImportInput}. */
|
|
79
78
|
type PrivateKeyImportInput = PublicKeyImportInput;
|
|
80
79
|
/** PBES2 encryption options for the encrypted PKCS#8 export/import functions. */
|
|
81
|
-
|
|
80
|
+
interface EncryptedPkcs8Options {
|
|
81
|
+
/** Password fed to PBKDF2 for key derivation. */
|
|
82
|
+
readonly password: string;
|
|
83
|
+
/** PBKDF2 iteration count. Default: `100_000`. */
|
|
84
|
+
readonly iterations?: number;
|
|
85
|
+
/** PBKDF2 salt. Default: 16 cryptographically random bytes. */
|
|
86
|
+
readonly salt?: Uint8Array;
|
|
87
|
+
/** AES-CBC initialization vector. Default: 16 cryptographically random bytes. */
|
|
88
|
+
readonly iv?: Uint8Array;
|
|
89
|
+
/** AES-CBC cipher. Default: `'AES-256-CBC'`. */
|
|
90
|
+
readonly cipher?: "AES-128-CBC" | "AES-192-CBC" | "AES-256-CBC";
|
|
91
|
+
/** PBKDF2 pseudo-random function. Default: `'HMAC-SHA-256'`. */
|
|
92
|
+
readonly prf?: "HMAC-SHA-1" | "HMAC-SHA-256";
|
|
93
|
+
}
|
|
82
94
|
/** Options for OpenSSL-style `Proc-Type: 4,ENCRYPTED` PEM encryption (PKCS#1/SEC1). */
|
|
83
95
|
interface LegacyPemEncryptionOptions {
|
|
84
96
|
/** Passphrase used to derive the encryption key. */
|
|
@@ -92,6 +104,7 @@ interface LegacyPemEncryptionOptions {
|
|
|
92
104
|
type ImportKeyErrorCode = "malformed";
|
|
93
105
|
/** Structured failure payload for key import. */
|
|
94
106
|
interface ImportKeyFailure extends Micro509Error<ImportKeyErrorCode> {
|
|
107
|
+
/** Always `false` for failures. */
|
|
95
108
|
readonly ok: false;
|
|
96
109
|
}
|
|
97
110
|
/**
|
|
@@ -114,6 +127,7 @@ type ImportKeyResult<T> = {
|
|
|
114
127
|
type ImportEncryptedKeyErrorCode = "malformed" | "invalid_password";
|
|
115
128
|
/** Structured failure payload for encrypted key import. */
|
|
116
129
|
interface ImportEncryptedKeyFailure extends Micro509Error<ImportEncryptedKeyErrorCode> {
|
|
130
|
+
/** Always `false` for failures. */
|
|
117
131
|
readonly ok: false;
|
|
118
132
|
}
|
|
119
133
|
/**
|
|
@@ -291,6 +305,36 @@ declare function exportEncryptedSec1Pem(privateKey: CryptoKey, options: LegacyPe
|
|
|
291
305
|
*/
|
|
292
306
|
declare function exportSpkiPem(publicKey: CryptoKey): Promise<string>;
|
|
293
307
|
/**
|
|
308
|
+
* Derive the matching public key from an imported (or generated) private key.
|
|
309
|
+
*
|
|
310
|
+
* The `import*` functions that read a PKCS#8 / PKCS#1 / SEC 1 / JWK private key
|
|
311
|
+
* return a bare `CryptoKey` with only `sign` usage — there is no accompanying
|
|
312
|
+
* public handle. This bridges that gap: it exports the private key's JWK,
|
|
313
|
+
* strips the private components, and re-imports the public half with `verify`
|
|
314
|
+
* usage, so callers can go straight to {@linkcode exportSpkiDer} /
|
|
315
|
+
* {@linkcode exportSpkiPem} (e.g. to rebuild a self-signed cert or distribute
|
|
316
|
+
* the public key when only the private key is on disk).
|
|
317
|
+
*
|
|
318
|
+
* Supports RSA (`n`/`e`), ECDSA (`x`/`y`), and Ed25519 (`x`). The derived key
|
|
319
|
+
* inherits the private key's algorithm parameters (hash, curve).
|
|
320
|
+
*
|
|
321
|
+
* @param privateKey - An extractable private `CryptoKey`
|
|
322
|
+
* @returns Extractable public `CryptoKey` with `verify` usage
|
|
323
|
+
*
|
|
324
|
+
* @throws {Error} If the key is not a private key, is non-extractable, or uses
|
|
325
|
+
* an unsupported key type
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```ts
|
|
329
|
+
* const privateKey = await importPkcs8PemOrThrow(pem, { kind: 'ecdsa', curve: 'P-256' });
|
|
330
|
+
* const publicKey = await derivePublicKey(privateKey);
|
|
331
|
+
* const spkiPem = await exportSpkiPem(publicKey);
|
|
332
|
+
* ```
|
|
333
|
+
*
|
|
334
|
+
* @see {@linkcode exportSpkiDer} for exporting the derived key
|
|
335
|
+
*/
|
|
336
|
+
declare function derivePublicKey(privateKey: CryptoKey): Promise<CryptoKey>;
|
|
337
|
+
/**
|
|
294
338
|
* Export a key as raw base64 (no PEM headers).
|
|
295
339
|
*
|
|
296
340
|
* Returns SPKI-encoded base64 for public keys, PKCS#8-encoded base64 for private keys.
|
|
@@ -305,21 +349,74 @@ declare function exportBinaryBase64(key: CryptoKey): Promise<string>;
|
|
|
305
349
|
/**
|
|
306
350
|
* Import a public key from DER-encoded SubjectPublicKeyInfo.
|
|
307
351
|
*
|
|
352
|
+
* When `algorithm` is omitted, the algorithm (and, for EC keys, the curve) is
|
|
353
|
+
* inferred from the SPKI's own AlgorithmIdentifier — useful for keys whose type
|
|
354
|
+
* isn't known ahead of time. Pass `algorithm` to additionally assert that the
|
|
355
|
+
* DER matches an expected algorithm.
|
|
356
|
+
*
|
|
357
|
+
* @param der - DER-encoded SubjectPublicKeyInfo bytes
|
|
358
|
+
* @param algorithm - Optional expected algorithm; must match key contents when given
|
|
359
|
+
* @returns Extractable CryptoKey with `verify` usage
|
|
360
|
+
*
|
|
361
|
+
* @throws {Error} If DER is malformed, encodes an unsupported algorithm, or doesn't match `algorithm`
|
|
362
|
+
*
|
|
363
|
+
* @see {@linkcode exportSpkiDer} for the inverse operation
|
|
364
|
+
* @see {@linkcode importSpkiPem} for PEM input
|
|
365
|
+
*/
|
|
366
|
+
declare function importSpkiDerOrThrow(der: Uint8Array, algorithm?: PublicKeyImportInput): Promise<CryptoKey>;
|
|
367
|
+
/**
|
|
368
|
+
* Import a public key from DER-encoded SubjectPublicKeyInfo.
|
|
369
|
+
*
|
|
308
370
|
* @see `importSpkiDerOrThrow` for the throwing variant
|
|
309
371
|
*/
|
|
310
|
-
declare function importSpkiDer(der: Uint8Array, algorithm
|
|
372
|
+
declare function importSpkiDer(der: Uint8Array, algorithm?: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
373
|
+
/**
|
|
374
|
+
* Import a public key from PEM-encoded SubjectPublicKeyInfo.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```ts
|
|
378
|
+
* const pem = `-----BEGIN PUBLIC KEY-----
|
|
379
|
+
* MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE...
|
|
380
|
+
* -----END PUBLIC KEY-----`;
|
|
381
|
+
* const key = await importSpkiPem(pem, { kind: 'ecdsa', curve: 'P-256' });
|
|
382
|
+
* ```
|
|
383
|
+
*
|
|
384
|
+
* @see {@linkcode exportSpkiPem} for the inverse operation
|
|
385
|
+
*/
|
|
386
|
+
declare function importSpkiPemOrThrow(pem: string, algorithm?: PublicKeyImportInput): Promise<CryptoKey>;
|
|
311
387
|
/**
|
|
312
388
|
* Import a public key from PEM-encoded SubjectPublicKeyInfo.
|
|
313
389
|
*
|
|
314
390
|
* @see `importSpkiPemOrThrow` for the throwing variant
|
|
315
391
|
*/
|
|
316
|
-
declare function importSpkiPem(pem: string, algorithm
|
|
392
|
+
declare function importSpkiPem(pem: string, algorithm?: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
393
|
+
/**
|
|
394
|
+
* Import a public key from base64-encoded SubjectPublicKeyInfo (no PEM headers).
|
|
395
|
+
*
|
|
396
|
+
* @see {@linkcode exportBinaryBase64} for the inverse operation
|
|
397
|
+
* @see {@linkcode importSpkiPem} for PEM input with headers
|
|
398
|
+
*/
|
|
399
|
+
declare function importSpkiBase64OrThrow(base64: string, algorithm?: PublicKeyImportInput): Promise<CryptoKey>;
|
|
317
400
|
/**
|
|
318
401
|
* Import a public key from base64-encoded SubjectPublicKeyInfo (no PEM headers).
|
|
319
402
|
*
|
|
320
403
|
* @see `importSpkiBase64OrThrow` for the throwing variant
|
|
321
404
|
*/
|
|
322
|
-
declare function importSpkiBase64(base64: string, algorithm
|
|
405
|
+
declare function importSpkiBase64(base64: string, algorithm?: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
406
|
+
/**
|
|
407
|
+
* Import a private key from DER-encoded PKCS#8 PrivateKeyInfo.
|
|
408
|
+
*
|
|
409
|
+
* @param der - DER-encoded PKCS#8 PrivateKeyInfo bytes
|
|
410
|
+
* @param algorithm - Expected algorithm (must match key contents)
|
|
411
|
+
* @returns Extractable CryptoKey with `sign` usage
|
|
412
|
+
*
|
|
413
|
+
* @throws {Error} If DER is malformed or algorithm doesn't match key
|
|
414
|
+
*
|
|
415
|
+
* @see {@linkcode exportPkcs8Der} for the inverse operation
|
|
416
|
+
* @see {@linkcode importPkcs8Pem} for PEM input
|
|
417
|
+
* @see {@linkcode importEncryptedPkcs8Der} for encrypted PKCS#8
|
|
418
|
+
*/
|
|
419
|
+
declare function importPkcs8DerOrThrow(der: Uint8Array, algorithm: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
323
420
|
/**
|
|
324
421
|
* Import a private key from DER-encoded PKCS#8 PrivateKeyInfo.
|
|
325
422
|
*
|
|
@@ -329,75 +426,202 @@ declare function importPkcs8Der(der: Uint8Array, algorithm: PrivateKeyImportInpu
|
|
|
329
426
|
/**
|
|
330
427
|
* Import a private key from PEM-encoded PKCS#8 PrivateKeyInfo.
|
|
331
428
|
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```ts
|
|
431
|
+
* const key = await importPkcs8Pem(pemString, { kind: 'ecdsa', curve: 'P-256' });
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
declare function importPkcs8PemOrThrow(pem: string, algorithm: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
435
|
+
/**
|
|
436
|
+
* Import a private key from PEM-encoded PKCS#8 PrivateKeyInfo.
|
|
437
|
+
*
|
|
332
438
|
* @see `importPkcs8PemOrThrow` for the throwing variant
|
|
333
439
|
*/
|
|
334
440
|
declare function importPkcs8Pem(pem: string, algorithm: PrivateKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
335
441
|
/**
|
|
336
442
|
* Import a private key from DER-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
337
443
|
*
|
|
444
|
+
* Decrypts the PBES2 envelope using the provided password, then imports the key.
|
|
445
|
+
*
|
|
446
|
+
* @param der - DER-encoded EncryptedPrivateKeyInfo bytes
|
|
447
|
+
* @param password - Decryption password
|
|
448
|
+
* @param algorithm - Expected algorithm (must match decrypted key)
|
|
449
|
+
*
|
|
450
|
+
* @throws {Error} If DER is malformed, password is wrong, or algorithm doesn't match
|
|
451
|
+
*
|
|
452
|
+
* @see {@linkcode exportEncryptedPkcs8Der} for the inverse operation
|
|
453
|
+
*/
|
|
454
|
+
declare function importEncryptedPkcs8DerOrThrow(der: Uint8Array, password: string, algorithm: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
455
|
+
/**
|
|
456
|
+
* Import a private key from DER-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
457
|
+
*
|
|
338
458
|
* @see `importEncryptedPkcs8DerOrThrow` for the throwing variant
|
|
339
459
|
*/
|
|
340
460
|
declare function importEncryptedPkcs8Der(der: Uint8Array, password: string, algorithm: PrivateKeyImportInput): Promise<ImportEncryptedKeyResult<CryptoKey>>;
|
|
341
461
|
/**
|
|
342
462
|
* Import a private key from PEM-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
343
463
|
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```ts
|
|
466
|
+
* const key = await importEncryptedPkcs8Pem(pem, 'secret', { kind: 'rsa' });
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
declare function importEncryptedPkcs8PemOrThrow(pem: string, password: string, algorithm: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
470
|
+
/**
|
|
471
|
+
* Import a private key from PEM-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
472
|
+
*
|
|
344
473
|
* @see `importEncryptedPkcs8PemOrThrow` for the throwing variant
|
|
345
474
|
*/
|
|
346
475
|
declare function importEncryptedPkcs8Pem(pem: string, password: string, algorithm: PrivateKeyImportInput): Promise<ImportEncryptedKeyResult<CryptoKey>>;
|
|
347
476
|
/**
|
|
348
477
|
* Import an RSA private key from DER-encoded PKCS#1 RSAPrivateKey.
|
|
349
478
|
*
|
|
479
|
+
* PKCS#1 is the legacy RSA-only format. Internally converts to PKCS#8 for import.
|
|
480
|
+
*
|
|
481
|
+
* @see {@linkcode exportPkcs1Der} for the inverse operation
|
|
482
|
+
* @see {@linkcode importPkcs1Pem} for PEM input
|
|
483
|
+
*/
|
|
484
|
+
declare function importPkcs1DerOrThrow(der: Uint8Array, algorithm?: ImportRsaKeyInput): Promise<CryptoKey>;
|
|
485
|
+
/**
|
|
486
|
+
* Import an RSA private key from DER-encoded PKCS#1 RSAPrivateKey.
|
|
487
|
+
*
|
|
350
488
|
* @see `importPkcs1DerOrThrow` for the throwing variant
|
|
351
489
|
*/
|
|
352
490
|
declare function importPkcs1Der(der: Uint8Array, algorithm?: ImportRsaKeyInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
353
491
|
/**
|
|
354
492
|
* Import an RSA private key from PEM-encoded PKCS#1 RSAPrivateKey.
|
|
355
493
|
*
|
|
494
|
+
* Expects the `-----BEGIN RSA PRIVATE KEY-----` PEM label.
|
|
495
|
+
*
|
|
496
|
+
* @see {@linkcode exportPkcs1Pem} for the inverse operation
|
|
497
|
+
* @see {@linkcode importEncryptedPkcs1Pem} for encrypted PEM
|
|
498
|
+
*/
|
|
499
|
+
declare function importPkcs1PemOrThrow(pem: string, algorithm?: ImportRsaKeyInput): Promise<CryptoKey>;
|
|
500
|
+
/**
|
|
501
|
+
* Import an RSA private key from PEM-encoded PKCS#1 RSAPrivateKey.
|
|
502
|
+
*
|
|
356
503
|
* @see `importPkcs1PemOrThrow` for the throwing variant
|
|
357
504
|
*/
|
|
358
505
|
declare function importPkcs1Pem(pem: string, algorithm?: ImportRsaKeyInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
359
506
|
/**
|
|
360
507
|
* Import an RSA private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
361
508
|
*
|
|
509
|
+
* Decrypts OpenSSL's traditional PEM encryption format.
|
|
510
|
+
*
|
|
511
|
+
* @see {@linkcode exportEncryptedPkcs1Pem} for the inverse operation
|
|
512
|
+
* @see {@linkcode importEncryptedPkcs8Pem} for modern PBES2 encryption
|
|
513
|
+
*/
|
|
514
|
+
declare function importEncryptedPkcs1PemOrThrow(pem: string, password: string, algorithm?: ImportRsaKeyInput): Promise<CryptoKey>;
|
|
515
|
+
/**
|
|
516
|
+
* Import an RSA private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
517
|
+
*
|
|
362
518
|
* @see `importEncryptedPkcs1PemOrThrow` for the throwing variant
|
|
363
519
|
*/
|
|
364
520
|
declare function importEncryptedPkcs1Pem(pem: string, password: string, algorithm?: ImportRsaKeyInput): Promise<ImportEncryptedKeyResult<CryptoKey>>;
|
|
365
521
|
/**
|
|
366
522
|
* Import a private key from base64-encoded PKCS#8 PrivateKeyInfo (no PEM headers).
|
|
367
523
|
*
|
|
524
|
+
* @see {@linkcode exportBinaryBase64} for the inverse operation
|
|
525
|
+
* @see {@linkcode importPkcs8Pem} for PEM input with headers
|
|
526
|
+
*/
|
|
527
|
+
declare function importPkcs8Base64OrThrow(base64: string, algorithm: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
528
|
+
/**
|
|
529
|
+
* Import a private key from base64-encoded PKCS#8 PrivateKeyInfo (no PEM headers).
|
|
530
|
+
*
|
|
368
531
|
* @see `importPkcs8Base64OrThrow` for the throwing variant
|
|
369
532
|
*/
|
|
370
533
|
declare function importPkcs8Base64(base64: string, algorithm: PrivateKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
371
534
|
/**
|
|
372
535
|
* Import an EC private key from DER-encoded SEC 1 ECPrivateKey.
|
|
373
536
|
*
|
|
537
|
+
* SEC 1 is the legacy EC-only format. Internally converts to PKCS#8 for import.
|
|
538
|
+
* When the ECPrivateKey carries the optional RFC 5915 `parameters [0]` field
|
|
539
|
+
* (OpenSSL always writes it), its named-curve OID must match `algorithm.curve`;
|
|
540
|
+
* when the field is absent, the caller-supplied curve is trusted.
|
|
541
|
+
*
|
|
542
|
+
* @throws {Error} If DER is not an ECPrivateKey or its embedded curve doesn't match `algorithm`
|
|
543
|
+
*
|
|
544
|
+
* @see {@linkcode exportSec1Der} for the inverse operation
|
|
545
|
+
* @see {@linkcode importSec1Pem} for PEM input
|
|
546
|
+
*/
|
|
547
|
+
declare function importSec1DerOrThrow(der: Uint8Array, algorithm: ImportEcKeyInput): Promise<CryptoKey>;
|
|
548
|
+
/**
|
|
549
|
+
* Import an EC private key from DER-encoded SEC 1 ECPrivateKey.
|
|
550
|
+
*
|
|
374
551
|
* @see `importSec1DerOrThrow` for the throwing variant
|
|
375
552
|
*/
|
|
376
553
|
declare function importSec1Der(der: Uint8Array, algorithm: ImportEcKeyInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
377
554
|
/**
|
|
378
555
|
* Import an EC private key from PEM-encoded SEC 1 ECPrivateKey.
|
|
379
556
|
*
|
|
557
|
+
* Expects the `-----BEGIN EC PRIVATE KEY-----` PEM label.
|
|
558
|
+
*
|
|
559
|
+
* @see {@linkcode exportSec1Pem} for the inverse operation
|
|
560
|
+
* @see {@linkcode importEncryptedSec1Pem} for encrypted PEM
|
|
561
|
+
*/
|
|
562
|
+
declare function importSec1PemOrThrow(pem: string, algorithm: ImportEcKeyInput): Promise<CryptoKey>;
|
|
563
|
+
/**
|
|
564
|
+
* Import an EC private key from PEM-encoded SEC 1 ECPrivateKey.
|
|
565
|
+
*
|
|
380
566
|
* @see `importSec1PemOrThrow` for the throwing variant
|
|
381
567
|
*/
|
|
382
568
|
declare function importSec1Pem(pem: string, algorithm: ImportEcKeyInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
383
569
|
/**
|
|
384
570
|
* Import an EC private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (SEC 1).
|
|
385
571
|
*
|
|
572
|
+
* Decrypts OpenSSL's traditional PEM encryption format.
|
|
573
|
+
*
|
|
574
|
+
* @see {@linkcode exportEncryptedSec1Pem} for the inverse operation
|
|
575
|
+
* @see {@linkcode importEncryptedPkcs8Pem} for modern PBES2 encryption
|
|
576
|
+
*/
|
|
577
|
+
declare function importEncryptedSec1PemOrThrow(pem: string, password: string, algorithm: ImportEcKeyInput): Promise<CryptoKey>;
|
|
578
|
+
/**
|
|
579
|
+
* Import an EC private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (SEC 1).
|
|
580
|
+
*
|
|
386
581
|
* @see `importEncryptedSec1PemOrThrow` for the throwing variant
|
|
387
582
|
*/
|
|
388
583
|
declare function importEncryptedSec1Pem(pem: string, password: string, algorithm: ImportEcKeyInput): Promise<ImportEncryptedKeyResult<CryptoKey>>;
|
|
389
584
|
/**
|
|
390
585
|
* Import a public verification key from a JSON Web Key.
|
|
391
586
|
*
|
|
587
|
+
* @param jwk - JSON Web Key object with public key components
|
|
588
|
+
* @param algorithm - Expected algorithm (must match JWK's `kty` and `crv`)
|
|
589
|
+
* @returns Extractable CryptoKey with `verify` usage
|
|
590
|
+
*
|
|
591
|
+
* @throws {Error} If JWK is malformed or algorithm doesn't match
|
|
592
|
+
*
|
|
593
|
+
* @see {@linkcode exportPublicJwk} for the inverse operation
|
|
594
|
+
*/
|
|
595
|
+
declare function importPublicJwkOrThrow(jwk: JsonWebKey, algorithm: PublicKeyImportInput): Promise<CryptoKey>;
|
|
596
|
+
/**
|
|
597
|
+
* Import a public verification key from a JSON Web Key.
|
|
598
|
+
*
|
|
392
599
|
* @see `importPublicJwkOrThrow` for the throwing variant
|
|
393
600
|
*/
|
|
394
601
|
declare function importPublicJwk(jwk: JsonWebKey, algorithm: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
395
602
|
/**
|
|
396
603
|
* Import a private signing key from a JSON Web Key.
|
|
397
604
|
*
|
|
605
|
+
* @param jwk - JSON Web Key object with private key components
|
|
606
|
+
* @param algorithm - Expected algorithm (must match JWK's `kty` and `crv`)
|
|
607
|
+
* @returns Extractable CryptoKey with `sign` usage
|
|
608
|
+
*
|
|
609
|
+
* @throws {Error} If JWK is malformed, lacks private key material, or algorithm doesn't match
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* ```ts
|
|
613
|
+
* const jwk = { kty: 'EC', crv: 'P-256', x: '...', y: '...', d: '...' };
|
|
614
|
+
* const key = await importPrivateJwk(jwk, { kind: 'ecdsa', curve: 'P-256' });
|
|
615
|
+
* ```
|
|
616
|
+
*
|
|
617
|
+
* @see {@linkcode exportPrivateJwk} for the inverse operation
|
|
618
|
+
*/
|
|
619
|
+
declare function importPrivateJwkOrThrow(jwk: JsonWebKey, algorithm: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
620
|
+
/**
|
|
621
|
+
* Import a private signing key from a JSON Web Key.
|
|
622
|
+
*
|
|
398
623
|
* @see `importPrivateJwkOrThrow` for the throwing variant
|
|
399
624
|
*/
|
|
400
625
|
declare function importPrivateJwk(jwk: JsonWebKey, algorithm: PrivateKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
401
626
|
//#endregion
|
|
402
|
-
export { EcKeyAlgorithmInput, EcNamedCurve, Ed25519KeyAlgorithmInput, EncryptedPkcs8Options, ImportEcKeyInput, ImportEd25519KeyInput, ImportEncryptedKeyErrorCode, ImportEncryptedKeyFailure, ImportEncryptedKeyResult, ImportKeyErrorCode, ImportKeyFailure, ImportKeyResult, ImportRsaKeyInput, KeyAlgorithmInput, KeyPairMaterial, LegacyPemEncryptionOptions, PrivateKeyImportInput, PublicKeyImportInput, RsaHash, RsaKeyAlgorithmInput, RsaScheme, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs8Der, importEncryptedPkcs8Pem, importEncryptedSec1Pem, importPkcs1Der, importPkcs1Pem, importPkcs8Base64, importPkcs8Der, importPkcs8Pem, importPrivateJwk, importPublicJwk, importSec1Der, importSec1Pem, importSpkiBase64, importSpkiDer, importSpkiPem };
|
|
403
|
-
//# sourceMappingURL=keys.d.ts.map
|
|
627
|
+
export { EcKeyAlgorithmInput, EcNamedCurve, Ed25519KeyAlgorithmInput, EncryptedPkcs8Options, ImportEcKeyInput, ImportEd25519KeyInput, ImportEncryptedKeyErrorCode, ImportEncryptedKeyFailure, ImportEncryptedKeyResult, ImportKeyErrorCode, ImportKeyFailure, ImportKeyResult, ImportRsaKeyInput, KeyAlgorithmInput, KeyPairMaterial, LegacyPemEncryptionOptions, PrivateKeyImportInput, PublicKeyImportInput, RsaHash, RsaKeyAlgorithmInput, RsaScheme, derivePublicKey, exportBinaryBase64, exportEncryptedPkcs1Pem, exportEncryptedPkcs8Der, exportEncryptedPkcs8Pem, exportEncryptedSec1Pem, exportPkcs1Der, exportPkcs1Pem, exportPkcs8Der, exportPkcs8Pem, exportPrivateJwk, exportPublicJwk, exportSec1Der, exportSec1Pem, exportSpkiDer, exportSpkiPem, generateKeyPair, importEncryptedPkcs1Pem, importEncryptedPkcs1PemOrThrow, importEncryptedPkcs8Der, importEncryptedPkcs8DerOrThrow, importEncryptedPkcs8Pem, importEncryptedPkcs8PemOrThrow, importEncryptedSec1Pem, importEncryptedSec1PemOrThrow, importPkcs1Der, importPkcs1DerOrThrow, importPkcs1Pem, importPkcs1PemOrThrow, importPkcs8Base64, importPkcs8Base64OrThrow, importPkcs8Der, importPkcs8DerOrThrow, importPkcs8Pem, importPkcs8PemOrThrow, importPrivateJwk, importPrivateJwkOrThrow, importPublicJwk, importPublicJwkOrThrow, importSec1Der, importSec1DerOrThrow, importSec1Pem, importSec1PemOrThrow, importSpkiBase64, importSpkiBase64OrThrow, importSpkiDer, importSpkiDerOrThrow, importSpkiPem, importSpkiPemOrThrow };
|