micro509 0.9.0 → 0.11.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 -4
- package/dist/index.js +16 -15
- package/dist/internal/asn1/asn1.js +145 -186
- package/dist/internal/asn1/asn1.js.map +1 -0
- package/dist/internal/asn1/der.js +210 -227
- package/dist/internal/asn1/der.js.map +1 -0
- package/dist/internal/asn1/oids.js +297 -101
- package/dist/internal/asn1/oids.js.map +1 -0
- package/dist/internal/asn1/oids2.js +69 -0
- package/dist/internal/asn1/oids2.js.map +1 -0
- package/dist/internal/crypto/algorithm-names.js +37 -35
- package/dist/internal/crypto/algorithm-names.js.map +1 -0
- package/dist/internal/crypto/ecdsa.js +25 -28
- package/dist/internal/crypto/ecdsa.js.map +1 -0
- package/dist/internal/crypto/hash.js +56 -117
- package/dist/internal/crypto/hash.js.map +1 -0
- package/dist/internal/crypto/pbes2.js +122 -133
- package/dist/internal/crypto/pbes2.js.map +1 -0
- package/dist/internal/crypto/rsa-pss.js +118 -124
- package/dist/internal/crypto/rsa-pss.js.map +1 -0
- package/dist/internal/crypto/sig-verify.js +87 -99
- package/dist/internal/crypto/sig-verify.js.map +1 -0
- package/dist/internal/crypto/signing.d.ts +12 -8
- package/dist/internal/crypto/signing.js +53 -55
- package/dist/internal/crypto/signing.js.map +1 -0
- package/dist/internal/crypto/webcrypto.js +5 -3
- package/dist/internal/crypto/webcrypto.js.map +1 -0
- package/dist/internal/shared/base64.js +10 -9
- package/dist/internal/shared/base64.js.map +1 -0
- package/dist/internal/shared/dn.js +50 -57
- package/dist/internal/shared/dn.js.map +1 -0
- package/dist/internal/shared/ip.js +43 -53
- package/dist/internal/shared/ip.js.map +1 -0
- package/dist/internal/verify/name-constraints-engine.js +211 -239
- package/dist/internal/verify/name-constraints-engine.js.map +1 -0
- package/dist/internal/verify/policy-engine.js +228 -247
- package/dist/internal/verify/policy-engine.js.map +1 -0
- package/dist/internal/verify/verify-path.js +213 -228
- package/dist/internal/verify/verify-path.js.map +1 -0
- package/dist/internal/x509/extension-bits.js +62 -59
- package/dist/internal/x509/extension-bits.js.map +1 -0
- package/dist/internal/x509/extension-registry.js +133 -164
- package/dist/internal/x509/extension-registry.js.map +1 -0
- package/dist/internal/x509/name-fields.js +35 -41
- package/dist/internal/x509/name-fields.js.map +1 -0
- package/dist/keys/keys.d.ts +583 -547
- package/dist/keys/keys.js +519 -431
- package/dist/keys/keys.js.map +1 -0
- package/dist/keys.js +2 -2
- package/dist/pem/pem.d.ts +46 -46
- package/dist/pem/pem.js +62 -81
- package/dist/pem/pem.js.map +1 -0
- package/dist/pem.js +2 -2
- package/dist/pkcs/pfx.d.ts +96 -80
- package/dist/pkcs/pfx.js +191 -231
- package/dist/pkcs/pfx.js.map +1 -0
- package/dist/pkcs/pkcs12-mac.d.ts +20 -18
- package/dist/pkcs/pkcs12-mac.js +90 -111
- package/dist/pkcs/pkcs12-mac.js.map +1 -0
- package/dist/pkcs/pkcs7.d.ts +118 -69
- package/dist/pkcs/pkcs7.js +401 -443
- package/dist/pkcs/pkcs7.js.map +1 -0
- package/dist/pkcs.d.ts +2 -2
- package/dist/pkcs.js +4 -4
- package/dist/result/result.d.ts +37 -32
- package/dist/result/result.js +46 -44
- package/dist/result/result.js.map +1 -0
- package/dist/result.js +2 -2
- package/dist/revocation/chain.d.ts +138 -119
- package/dist/revocation/chain.js +248 -281
- package/dist/revocation/chain.js.map +1 -0
- package/dist/revocation/crl.d.ts +125 -123
- package/dist/revocation/crl.js +653 -745
- package/dist/revocation/crl.js.map +1 -0
- package/dist/revocation/ocsp.d.ts +183 -177
- package/dist/revocation/ocsp.js +579 -636
- package/dist/revocation/ocsp.js.map +1 -0
- package/dist/revocation/revocation.d.ts +26 -26
- package/dist/revocation/revocation.js +104 -125
- package/dist/revocation/revocation.js.map +1 -0
- package/dist/revocation.js +5 -5
- package/dist/verify/identity.d.ts +42 -42
- package/dist/verify/identity.js +158 -167
- package/dist/verify/identity.js.map +1 -0
- package/dist/verify/name-constraints.d.ts +7 -7
- package/dist/verify/policy.d.ts +10 -10
- package/dist/verify/verify.d.ts +163 -163
- package/dist/verify/verify.js +396 -392
- package/dist/verify/verify.js.map +1 -0
- package/dist/verify.js +3 -3
- package/dist/x509/certificate.d.ts +117 -117
- package/dist/x509/certificate.js +51 -60
- package/dist/x509/certificate.js.map +1 -0
- package/dist/x509/csr.d.ts +25 -25
- package/dist/x509/csr.js +26 -30
- package/dist/x509/csr.js.map +1 -0
- package/dist/x509/extensions.d.ts +228 -184
- package/dist/x509/extensions.js +175 -200
- package/dist/x509/extensions.js.map +1 -0
- package/dist/x509/fingerprint.d.ts +55 -0
- package/dist/x509/fingerprint.js +55 -0
- package/dist/x509/fingerprint.js.map +1 -0
- package/dist/x509/name.d.ts +94 -93
- package/dist/x509/name.js +30 -29
- package/dist/x509/name.js.map +1 -0
- package/dist/x509/parse.d.ts +288 -185
- package/dist/x509/parse.js +762 -677
- package/dist/x509/parse.js.map +1 -0
- package/dist/x509.d.ts +3 -2
- package/dist/x509.js +7 -6
- package/package.json +79 -41
package/dist/keys/keys.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { ErrorResult, Micro509Error } from "../result/result.js";
|
|
2
|
-
|
|
3
2
|
//#region src/keys/keys.d.ts
|
|
4
3
|
/** Hash algorithm paired with an RSA key. */
|
|
5
4
|
type RsaHash = "SHA-256" | "SHA-384" | "SHA-512";
|
|
6
5
|
/** RSA signature padding scheme. */
|
|
7
6
|
type RsaSignatureScheme = "pkcs1-v1_5" | "pss";
|
|
8
7
|
/**
|
|
9
|
-
* RSA padding scheme: a signature scheme, or `'oaep'` for RSA-OAEP encryption
|
|
10
|
-
* keys (usable with {@linkcode encryptRsaOaep} / {@linkcode decryptRsaOaep}).
|
|
11
|
-
*/
|
|
8
|
+
* RSA padding scheme: a signature scheme, or `'oaep'` for RSA-OAEP encryption
|
|
9
|
+
* keys (usable with {@linkcode encryptRsaOaep} / {@linkcode decryptRsaOaep}).
|
|
10
|
+
*/
|
|
12
11
|
type RsaScheme = RsaSignatureScheme | "oaep";
|
|
13
12
|
/** NIST elliptic curve for ECDSA keys. */
|
|
14
13
|
type EcNamedCurve = "P-256" | "P-384" | "P-521";
|
|
@@ -21,9 +20,9 @@ interface RsaKeyAlgorithmInput {
|
|
|
21
20
|
/** Hash algorithm for the key. Defaults to `'SHA-256'`. */
|
|
22
21
|
readonly hash?: RsaHash;
|
|
23
22
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
* Padding scheme. Defaults to `'pkcs1-v1_5'`. Pass `'oaep'` to generate an
|
|
24
|
+
* RSA-OAEP encryption pair (`encrypt`/`decrypt` usages instead of `sign`/`verify`).
|
|
25
|
+
*/
|
|
27
26
|
readonly scheme?: RsaScheme;
|
|
28
27
|
}
|
|
29
28
|
/** ECDSA variant of {@linkcode KeyAlgorithmInput}. */
|
|
@@ -66,9 +65,9 @@ interface ImportRsaKeyInput {
|
|
|
66
65
|
/** Hash algorithm. Defaults to `'SHA-256'`. */
|
|
67
66
|
readonly hash?: RsaHash;
|
|
68
67
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
* Padding scheme. Defaults to `'pkcs1-v1_5'`. Pass `'oaep'` to import an
|
|
69
|
+
* RSA-OAEP encryption key (`encrypt`/`decrypt` usage instead of `verify`/`sign`).
|
|
70
|
+
*/
|
|
72
71
|
readonly scheme?: RsaScheme;
|
|
73
72
|
}
|
|
74
73
|
/** ECDSA variant of {@linkcode PublicKeyImportInput} / {@linkcode PrivateKeyImportInput}. */
|
|
@@ -119,22 +118,22 @@ interface ImportKeyFailure extends Micro509Error<ImportKeyErrorCode> {
|
|
|
119
118
|
readonly ok: false;
|
|
120
119
|
}
|
|
121
120
|
/**
|
|
122
|
-
* Success-or-failure result returned by the public `import*` key functions.
|
|
123
|
-
*
|
|
124
|
-
* On failure, `code` is always `'malformed'`: structurally invalid input,
|
|
125
|
-
* algorithm mismatches, and wrong-password decryption failures all surface
|
|
126
|
-
* the same way (see the throwing `*OrThrow` variants for raw error messages).
|
|
127
|
-
*/
|
|
121
|
+
* Success-or-failure result returned by the public `import*` key functions.
|
|
122
|
+
*
|
|
123
|
+
* On failure, `code` is always `'malformed'`: structurally invalid input,
|
|
124
|
+
* algorithm mismatches, and wrong-password decryption failures all surface
|
|
125
|
+
* the same way (see the throwing `*OrThrow` variants for raw error messages).
|
|
126
|
+
*/
|
|
128
127
|
type ImportKeyResult<T> = {
|
|
129
128
|
readonly ok: true;
|
|
130
129
|
readonly value: T;
|
|
131
130
|
} | ErrorResult<ImportKeyErrorCode, Record<never, never>, ImportKeyFailure>;
|
|
132
131
|
/**
|
|
133
|
-
* Machine-readable failure reason for the `importEncrypted*` key functions.
|
|
134
|
-
*
|
|
135
|
-
* Distinguishes a wrong decryption password (`'invalid_password'`) from
|
|
136
|
-
* structurally invalid input or algorithm mismatches (`'malformed'`).
|
|
137
|
-
*/
|
|
132
|
+
* Machine-readable failure reason for the `importEncrypted*` key functions.
|
|
133
|
+
*
|
|
134
|
+
* Distinguishes a wrong decryption password (`'invalid_password'`) from
|
|
135
|
+
* structurally invalid input or algorithm mismatches (`'malformed'`).
|
|
136
|
+
*/
|
|
138
137
|
type ImportEncryptedKeyErrorCode = "malformed" | "invalid_password";
|
|
139
138
|
/** Structured failure payload for encrypted key import. */
|
|
140
139
|
interface ImportEncryptedKeyFailure extends Micro509Error<ImportEncryptedKeyErrorCode> {
|
|
@@ -142,11 +141,11 @@ interface ImportEncryptedKeyFailure extends Micro509Error<ImportEncryptedKeyErro
|
|
|
142
141
|
readonly ok: false;
|
|
143
142
|
}
|
|
144
143
|
/**
|
|
145
|
-
* Success-or-failure result returned by the public `importEncrypted*` key functions.
|
|
146
|
-
*
|
|
147
|
-
* On failure, `code` is `'invalid_password'` when decryption failed (wrong
|
|
148
|
-
* password or corrupted ciphertext) and `'malformed'` for everything else.
|
|
149
|
-
*/
|
|
144
|
+
* Success-or-failure result returned by the public `importEncrypted*` key functions.
|
|
145
|
+
*
|
|
146
|
+
* On failure, `code` is `'invalid_password'` when decryption failed (wrong
|
|
147
|
+
* password or corrupted ciphertext) and `'malformed'` for everything else.
|
|
148
|
+
*/
|
|
150
149
|
type ImportEncryptedKeyResult<T> = {
|
|
151
150
|
readonly ok: true;
|
|
152
151
|
readonly value: T;
|
|
@@ -154,18 +153,18 @@ type ImportEncryptedKeyResult<T> = {
|
|
|
154
153
|
/** Options shared by {@linkcode encryptRsaOaep} and {@linkcode decryptRsaOaep}. */
|
|
155
154
|
interface RsaOaepOptions {
|
|
156
155
|
/**
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
* Optional OAEP label bound to the ciphertext. Not encrypted, but decryption
|
|
157
|
+
* fails unless the exact same label is presented. Default: empty.
|
|
158
|
+
*/
|
|
160
159
|
readonly label?: Uint8Array;
|
|
161
160
|
}
|
|
162
161
|
/**
|
|
163
|
-
* Machine-readable failure reason for {@linkcode encryptRsaOaep}.
|
|
164
|
-
*
|
|
165
|
-
* `'invalid_key'` when the key is not an RSA-OAEP public key with `encrypt`
|
|
166
|
-
* usage; `'message_too_long'` when the plaintext exceeds the OAEP capacity of
|
|
167
|
-
* the key (modulus bytes − 2 × hash bytes − 2).
|
|
168
|
-
*/
|
|
162
|
+
* Machine-readable failure reason for {@linkcode encryptRsaOaep}.
|
|
163
|
+
*
|
|
164
|
+
* `'invalid_key'` when the key is not an RSA-OAEP public key with `encrypt`
|
|
165
|
+
* usage; `'message_too_long'` when the plaintext exceeds the OAEP capacity of
|
|
166
|
+
* the key (modulus bytes − 2 × hash bytes − 2).
|
|
167
|
+
*/
|
|
169
168
|
type EncryptRsaOaepErrorCode = "invalid_key" | "message_too_long";
|
|
170
169
|
/** Structured failure payload for {@linkcode encryptRsaOaep}. */
|
|
171
170
|
interface EncryptRsaOaepFailure extends Micro509Error<EncryptRsaOaepErrorCode> {
|
|
@@ -178,13 +177,13 @@ type EncryptRsaOaepResult = {
|
|
|
178
177
|
readonly value: Uint8Array;
|
|
179
178
|
} | ErrorResult<EncryptRsaOaepErrorCode, Record<never, never>, EncryptRsaOaepFailure>;
|
|
180
179
|
/**
|
|
181
|
-
* Machine-readable failure reason for {@linkcode decryptRsaOaep}.
|
|
182
|
-
*
|
|
183
|
-
* `'invalid_key'` when the key is not an RSA-OAEP private key with `decrypt`
|
|
184
|
-
* usage; `'decryption_failed'` for every ciphertext-level failure (wrong key,
|
|
185
|
-
* wrong label, tampered or truncated ciphertext) — OAEP deliberately does not
|
|
186
|
-
* reveal which.
|
|
187
|
-
*/
|
|
180
|
+
* Machine-readable failure reason for {@linkcode decryptRsaOaep}.
|
|
181
|
+
*
|
|
182
|
+
* `'invalid_key'` when the key is not an RSA-OAEP private key with `decrypt`
|
|
183
|
+
* usage; `'decryption_failed'` for every ciphertext-level failure (wrong key,
|
|
184
|
+
* wrong label, tampered or truncated ciphertext) — OAEP deliberately does not
|
|
185
|
+
* reveal which.
|
|
186
|
+
*/
|
|
188
187
|
type DecryptRsaOaepErrorCode = "invalid_key" | "decryption_failed";
|
|
189
188
|
/** Structured failure payload for {@linkcode decryptRsaOaep}. */
|
|
190
189
|
interface DecryptRsaOaepFailure extends Micro509Error<DecryptRsaOaepErrorCode> {
|
|
@@ -197,574 +196,611 @@ type DecryptRsaOaepResult = {
|
|
|
197
196
|
readonly value: Uint8Array;
|
|
198
197
|
} | ErrorResult<DecryptRsaOaepErrorCode, Record<never, never>, DecryptRsaOaepFailure>;
|
|
199
198
|
/**
|
|
200
|
-
* Generate an asymmetric key pair for signing and verification, or — with
|
|
201
|
-
* `{ kind: 'rsa', scheme: 'oaep' }` — for RSA-OAEP encryption and decryption.
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* ```ts
|
|
205
|
-
* const ecKeys = await generateKeyPair({ kind: 'ecdsa', curve: 'P-384' });
|
|
206
|
-
* const rsaKeys = await generateKeyPair({ kind: 'rsa', modulusLength: 4096 });
|
|
207
|
-
* const edKeys = await generateKeyPair({ kind: 'ed25519' });
|
|
208
|
-
* const oaepKeys = await generateKeyPair({ kind: 'rsa', scheme: 'oaep' });
|
|
209
|
-
*
|
|
210
|
-
* // Default: ECDSA P-256
|
|
211
|
-
* const keys = await generateKeyPair();
|
|
212
|
-
* const pem = await keys.exportPkcs8Pem();
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
199
|
+
* Generate an asymmetric key pair for signing and verification, or — with
|
|
200
|
+
* `{ kind: 'rsa', scheme: 'oaep' }` — for RSA-OAEP encryption and decryption.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* const ecKeys = await generateKeyPair({ kind: 'ecdsa', curve: 'P-384' });
|
|
205
|
+
* const rsaKeys = await generateKeyPair({ kind: 'rsa', modulusLength: 4096 });
|
|
206
|
+
* const edKeys = await generateKeyPair({ kind: 'ed25519' });
|
|
207
|
+
* const oaepKeys = await generateKeyPair({ kind: 'rsa', scheme: 'oaep' });
|
|
208
|
+
*
|
|
209
|
+
* // Default: ECDSA P-256
|
|
210
|
+
* const keys = await generateKeyPair();
|
|
211
|
+
* const pem = await keys.exportPkcs8Pem();
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
215
214
|
declare function generateKeyPair(algorithm?: KeyAlgorithmInput): Promise<KeyPairMaterial>;
|
|
216
215
|
/**
|
|
217
|
-
* Export a public key as DER-encoded SubjectPublicKeyInfo.
|
|
218
|
-
*
|
|
219
|
-
* @see {@linkcode importSpkiDer} for the inverse operation
|
|
220
|
-
* @see {@linkcode exportSpkiPem} for PEM output
|
|
221
|
-
*/
|
|
216
|
+
* Export a public key as DER-encoded SubjectPublicKeyInfo.
|
|
217
|
+
*
|
|
218
|
+
* @see {@linkcode importSpkiDer} for the inverse operation
|
|
219
|
+
* @see {@linkcode exportSpkiPem} for PEM output
|
|
220
|
+
*/
|
|
222
221
|
declare function exportSpkiDer(publicKey: CryptoKey): Promise<Uint8Array>;
|
|
223
222
|
/**
|
|
224
|
-
* Export a private key as DER-encoded PKCS#8 PrivateKeyInfo.
|
|
225
|
-
*
|
|
226
|
-
* @see {@linkcode importPkcs8Der} for the inverse operation
|
|
227
|
-
* @see {@linkcode exportPkcs8Pem} for PEM output
|
|
228
|
-
* @see {@linkcode exportEncryptedPkcs8Der} for password-protected export
|
|
229
|
-
*/
|
|
223
|
+
* Export a private key as DER-encoded PKCS#8 PrivateKeyInfo.
|
|
224
|
+
*
|
|
225
|
+
* @see {@linkcode importPkcs8Der} for the inverse operation
|
|
226
|
+
* @see {@linkcode exportPkcs8Pem} for PEM output
|
|
227
|
+
* @see {@linkcode exportEncryptedPkcs8Der} for password-protected export
|
|
228
|
+
*/
|
|
230
229
|
declare function exportPkcs8Der(privateKey: CryptoKey): Promise<Uint8Array>;
|
|
231
230
|
/**
|
|
232
|
-
* Export a public key as a JSON Web Key.
|
|
233
|
-
*
|
|
234
|
-
* @example
|
|
235
|
-
* ```ts
|
|
236
|
-
* const keys = await generateKeyPair({ kind: 'ecdsa', curve: 'P-256' });
|
|
237
|
-
* const jwk = await exportPublicJwk(keys.publicKey);
|
|
238
|
-
* ```
|
|
239
|
-
*/
|
|
231
|
+
* Export a public key as a JSON Web Key.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* const keys = await generateKeyPair({ kind: 'ecdsa', curve: 'P-256' });
|
|
236
|
+
* const jwk = await exportPublicJwk(keys.publicKey);
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
240
239
|
declare function exportPublicJwk(publicKey: CryptoKey): Promise<JsonWebKey>;
|
|
241
240
|
/**
|
|
242
|
-
* Export a private key as a JSON Web Key.
|
|
243
|
-
*
|
|
244
|
-
* @see {@linkcode importPrivateJwk} for the inverse operation
|
|
245
|
-
* @see {@linkcode exportPublicJwk} for public key export
|
|
246
|
-
*/
|
|
241
|
+
* Export a private key as a JSON Web Key.
|
|
242
|
+
*
|
|
243
|
+
* @see {@linkcode importPrivateJwk} for the inverse operation
|
|
244
|
+
* @see {@linkcode exportPublicJwk} for public key export
|
|
245
|
+
*/
|
|
247
246
|
declare function exportPrivateJwk(privateKey: CryptoKey): Promise<JsonWebKey>;
|
|
248
247
|
/**
|
|
249
|
-
* Export a private key as PEM-encoded PKCS#8 PrivateKeyInfo.
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```ts
|
|
253
|
-
* const keys = await generateKeyPair();
|
|
254
|
-
* const pem = await exportPkcs8Pem(keys.privateKey);
|
|
255
|
-
* // -----BEGIN PRIVATE KEY-----
|
|
256
|
-
* // MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEH...
|
|
257
|
-
* // -----END PRIVATE KEY-----
|
|
258
|
-
* ```
|
|
259
|
-
*
|
|
260
|
-
* @see {@linkcode importPkcs8Pem} for the inverse operation
|
|
261
|
-
* @see {@linkcode exportEncryptedPkcs8Pem} for password-protected export
|
|
262
|
-
*/
|
|
248
|
+
* Export a private key as PEM-encoded PKCS#8 PrivateKeyInfo.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```ts
|
|
252
|
+
* const keys = await generateKeyPair();
|
|
253
|
+
* const pem = await exportPkcs8Pem(keys.privateKey);
|
|
254
|
+
* // -----BEGIN PRIVATE KEY-----
|
|
255
|
+
* // MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEH...
|
|
256
|
+
* // -----END PRIVATE KEY-----
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* @see {@linkcode importPkcs8Pem} for the inverse operation
|
|
260
|
+
* @see {@linkcode exportEncryptedPkcs8Pem} for password-protected export
|
|
261
|
+
*/
|
|
263
262
|
declare function exportPkcs8Pem(privateKey: CryptoKey): Promise<string>;
|
|
264
263
|
/**
|
|
265
|
-
* Export a private key as DER-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
266
|
-
*
|
|
267
|
-
* Uses PBES2 (PKCS#5 v2.1) with AES-CBC and PBKDF2. Compatible with OpenSSL.
|
|
268
|
-
*
|
|
269
|
-
* @param privateKey - The private key to export
|
|
270
|
-
* @param options - Encryption options including password and optional algorithm settings
|
|
271
|
-
*
|
|
272
|
-
* @see {@linkcode importEncryptedPkcs8Der} for the inverse operation
|
|
273
|
-
* @see {@linkcode exportEncryptedPkcs8Pem} for PEM output
|
|
274
|
-
*/
|
|
264
|
+
* Export a private key as DER-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
265
|
+
*
|
|
266
|
+
* Uses PBES2 (PKCS#5 v2.1) with AES-CBC and PBKDF2. Compatible with OpenSSL.
|
|
267
|
+
*
|
|
268
|
+
* @param privateKey - The private key to export
|
|
269
|
+
* @param options - Encryption options including password and optional algorithm settings
|
|
270
|
+
*
|
|
271
|
+
* @see {@linkcode importEncryptedPkcs8Der} for the inverse operation
|
|
272
|
+
* @see {@linkcode exportEncryptedPkcs8Pem} for PEM output
|
|
273
|
+
*/
|
|
275
274
|
declare function exportEncryptedPkcs8Der(privateKey: CryptoKey, options: EncryptedPkcs8Options): Promise<Uint8Array>;
|
|
276
275
|
/**
|
|
277
|
-
* Export a private key as PEM-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* ```ts
|
|
281
|
-
* const keys = await generateKeyPair();
|
|
282
|
-
* const pem = await exportEncryptedPkcs8Pem(keys.privateKey, { password: 'secret' });
|
|
283
|
-
* // -----BEGIN ENCRYPTED PRIVATE KEY-----
|
|
284
|
-
* // MIHsMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAc...
|
|
285
|
-
* // -----END ENCRYPTED PRIVATE KEY-----
|
|
286
|
-
* ```
|
|
287
|
-
*
|
|
288
|
-
* @see {@linkcode importEncryptedPkcs8Pem} for the inverse operation
|
|
289
|
-
*/
|
|
276
|
+
* Export a private key as PEM-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```ts
|
|
280
|
+
* const keys = await generateKeyPair();
|
|
281
|
+
* const pem = await exportEncryptedPkcs8Pem(keys.privateKey, { password: 'secret' });
|
|
282
|
+
* // -----BEGIN ENCRYPTED PRIVATE KEY-----
|
|
283
|
+
* // MIHsMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAc...
|
|
284
|
+
* // -----END ENCRYPTED PRIVATE KEY-----
|
|
285
|
+
* ```
|
|
286
|
+
*
|
|
287
|
+
* @see {@linkcode importEncryptedPkcs8Pem} for the inverse operation
|
|
288
|
+
*/
|
|
290
289
|
declare function exportEncryptedPkcs8Pem(privateKey: CryptoKey, options: EncryptedPkcs8Options): Promise<string>;
|
|
291
290
|
/**
|
|
292
|
-
* Export an RSA private key as DER-encoded PKCS#1 RSAPrivateKey.
|
|
293
|
-
*
|
|
294
|
-
* PKCS#1 is the legacy RSA-only format. For algorithm-agnostic export, use
|
|
295
|
-
* {@linkcode exportPkcs8Der}.
|
|
296
|
-
*
|
|
297
|
-
* @throws {Error} If the key is not an RSA key
|
|
298
|
-
*
|
|
299
|
-
* @see {@linkcode importPkcs1Der} for the inverse operation
|
|
300
|
-
* @see {@linkcode exportPkcs1Pem} for PEM output
|
|
301
|
-
*/
|
|
291
|
+
* Export an RSA private key as DER-encoded PKCS#1 RSAPrivateKey.
|
|
292
|
+
*
|
|
293
|
+
* PKCS#1 is the legacy RSA-only format. For algorithm-agnostic export, use
|
|
294
|
+
* {@linkcode exportPkcs8Der}.
|
|
295
|
+
*
|
|
296
|
+
* @throws {Error} If the key is not an RSA key
|
|
297
|
+
*
|
|
298
|
+
* @see {@linkcode importPkcs1Der} for the inverse operation
|
|
299
|
+
* @see {@linkcode exportPkcs1Pem} for PEM output
|
|
300
|
+
*/
|
|
302
301
|
declare function exportPkcs1Der(privateKey: CryptoKey): Promise<Uint8Array>;
|
|
303
302
|
/**
|
|
304
|
-
* Export an RSA private key as PEM-encoded PKCS#1 RSAPrivateKey.
|
|
305
|
-
*
|
|
306
|
-
* @throws {Error} If the key is not an RSA key
|
|
307
|
-
*
|
|
308
|
-
* @see {@linkcode importPkcs1Pem} for the inverse operation
|
|
309
|
-
* @see {@linkcode exportEncryptedPkcs1Pem} for password-protected export
|
|
310
|
-
*/
|
|
303
|
+
* Export an RSA private key as PEM-encoded PKCS#1 RSAPrivateKey.
|
|
304
|
+
*
|
|
305
|
+
* @throws {Error} If the key is not an RSA key
|
|
306
|
+
*
|
|
307
|
+
* @see {@linkcode importPkcs1Pem} for the inverse operation
|
|
308
|
+
* @see {@linkcode exportEncryptedPkcs1Pem} for password-protected export
|
|
309
|
+
*/
|
|
311
310
|
declare function exportPkcs1Pem(privateKey: CryptoKey): Promise<string>;
|
|
312
311
|
/**
|
|
313
|
-
* Export an RSA private key as legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
314
|
-
*
|
|
315
|
-
* Uses OpenSSL's traditional PEM encryption with MD5-based key derivation.
|
|
316
|
-
* For modern encryption, prefer {@linkcode exportEncryptedPkcs8Pem}.
|
|
317
|
-
*
|
|
318
|
-
* @throws {Error} If the key is not an RSA key
|
|
319
|
-
*
|
|
320
|
-
* @see {@linkcode importEncryptedPkcs1Pem} for the inverse operation
|
|
321
|
-
*/
|
|
312
|
+
* Export an RSA private key as legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
313
|
+
*
|
|
314
|
+
* Uses OpenSSL's traditional PEM encryption with MD5-based key derivation.
|
|
315
|
+
* For modern encryption, prefer {@linkcode exportEncryptedPkcs8Pem}.
|
|
316
|
+
*
|
|
317
|
+
* @throws {Error} If the key is not an RSA key
|
|
318
|
+
*
|
|
319
|
+
* @see {@linkcode importEncryptedPkcs1Pem} for the inverse operation
|
|
320
|
+
*/
|
|
322
321
|
declare function exportEncryptedPkcs1Pem(privateKey: CryptoKey, options: LegacyPemEncryptionOptions): Promise<string>;
|
|
323
322
|
/**
|
|
324
|
-
* Export an EC private key as DER-encoded SEC 1 ECPrivateKey.
|
|
325
|
-
*
|
|
326
|
-
* SEC 1 is the legacy EC-only format. For algorithm-agnostic export, use
|
|
327
|
-
* {@linkcode exportPkcs8Der}.
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
|
|
323
|
+
* Export an EC private key as DER-encoded SEC 1 ECPrivateKey.
|
|
324
|
+
*
|
|
325
|
+
* SEC 1 is the legacy EC-only format. For algorithm-agnostic export, use
|
|
326
|
+
* {@linkcode exportPkcs8Der}.
|
|
327
|
+
*
|
|
328
|
+
* The output always carries the RFC 5915 `parameters [0]` named curve
|
|
329
|
+
* (matching OpenSSL), so it re-imports via {@linkcode importSec1Der} without
|
|
330
|
+
* an explicit curve.
|
|
331
|
+
*
|
|
332
|
+
* @throws {Error} If the key is not an EC key
|
|
333
|
+
*
|
|
334
|
+
* @see {@linkcode importSec1Der} for the inverse operation
|
|
335
|
+
* @see {@linkcode exportSec1Pem} for PEM output
|
|
336
|
+
*/
|
|
334
337
|
declare function exportSec1Der(privateKey: CryptoKey): Promise<Uint8Array>;
|
|
335
338
|
/**
|
|
336
|
-
* Export an EC private key as PEM-encoded SEC 1 ECPrivateKey.
|
|
337
|
-
*
|
|
338
|
-
* @throws {Error} If the key is not an EC key
|
|
339
|
-
*
|
|
340
|
-
* @see {@linkcode importSec1Pem} for the inverse operation
|
|
341
|
-
* @see {@linkcode exportEncryptedSec1Pem} for password-protected export
|
|
342
|
-
*/
|
|
339
|
+
* Export an EC private key as PEM-encoded SEC 1 ECPrivateKey.
|
|
340
|
+
*
|
|
341
|
+
* @throws {Error} If the key is not an EC key
|
|
342
|
+
*
|
|
343
|
+
* @see {@linkcode importSec1Pem} for the inverse operation
|
|
344
|
+
* @see {@linkcode exportEncryptedSec1Pem} for password-protected export
|
|
345
|
+
*/
|
|
343
346
|
declare function exportSec1Pem(privateKey: CryptoKey): Promise<string>;
|
|
344
347
|
/**
|
|
345
|
-
* Export an EC private key as legacy `Proc-Type: 4,ENCRYPTED` PEM (SEC 1).
|
|
346
|
-
*
|
|
347
|
-
* Uses OpenSSL's traditional PEM encryption with MD5-based key derivation.
|
|
348
|
-
* For modern encryption, prefer {@linkcode exportEncryptedPkcs8Pem}.
|
|
349
|
-
*
|
|
350
|
-
* @throws {Error} If the key is not an EC key
|
|
351
|
-
*
|
|
352
|
-
* @see {@linkcode importEncryptedSec1Pem} for the inverse operation
|
|
353
|
-
*/
|
|
348
|
+
* Export an EC private key as legacy `Proc-Type: 4,ENCRYPTED` PEM (SEC 1).
|
|
349
|
+
*
|
|
350
|
+
* Uses OpenSSL's traditional PEM encryption with MD5-based key derivation.
|
|
351
|
+
* For modern encryption, prefer {@linkcode exportEncryptedPkcs8Pem}.
|
|
352
|
+
*
|
|
353
|
+
* @throws {Error} If the key is not an EC key
|
|
354
|
+
*
|
|
355
|
+
* @see {@linkcode importEncryptedSec1Pem} for the inverse operation
|
|
356
|
+
*/
|
|
354
357
|
declare function exportEncryptedSec1Pem(privateKey: CryptoKey, options: LegacyPemEncryptionOptions): Promise<string>;
|
|
355
358
|
/**
|
|
356
|
-
* Export a public key as PEM-encoded SubjectPublicKeyInfo.
|
|
357
|
-
*
|
|
358
|
-
* @example
|
|
359
|
-
* ```ts
|
|
360
|
-
* const keys = await generateKeyPair();
|
|
361
|
-
* const pem = await exportSpkiPem(keys.publicKey);
|
|
362
|
-
* ```
|
|
363
|
-
*/
|
|
359
|
+
* Export a public key as PEM-encoded SubjectPublicKeyInfo.
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```ts
|
|
363
|
+
* const keys = await generateKeyPair();
|
|
364
|
+
* const pem = await exportSpkiPem(keys.publicKey);
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
364
367
|
declare function exportSpkiPem(publicKey: CryptoKey): Promise<string>;
|
|
365
368
|
/**
|
|
366
|
-
* Derive the matching public key from an imported (or generated) private key.
|
|
367
|
-
*
|
|
368
|
-
* The `import*` functions that read a PKCS#8 / PKCS#1 / SEC 1 / JWK private key
|
|
369
|
-
* return a bare `CryptoKey` with only `sign` (or, for RSA-OAEP, `decrypt`)
|
|
370
|
-
* usage — there is no accompanying public handle. This bridges that gap: it
|
|
371
|
-
* exports the private key's JWK, strips the private components, and re-imports
|
|
372
|
-
* the public half with `verify` (RSA-OAEP: `encrypt`) usage, so callers can go
|
|
373
|
-
* straight to {@linkcode exportSpkiDer} / {@linkcode exportSpkiPem} (e.g. to
|
|
374
|
-
* rebuild a self-signed cert or distribute the public key when only the
|
|
375
|
-
* private key is on disk).
|
|
376
|
-
*
|
|
377
|
-
* Supports RSA (`n`/`e`), ECDSA (`x`/`y`), and Ed25519 (`x`). The derived key
|
|
378
|
-
* inherits the private key's algorithm parameters (hash, curve).
|
|
379
|
-
*
|
|
380
|
-
* @param privateKey - An extractable private `CryptoKey`
|
|
381
|
-
* @returns Extractable public `CryptoKey` with `verify` (RSA-OAEP: `encrypt`) usage
|
|
382
|
-
*
|
|
383
|
-
* @throws {Error} If the key is not a private key, is non-extractable, or uses
|
|
384
|
-
* an unsupported key type
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
* ```ts
|
|
388
|
-
* const privateKey = await importPkcs8PemOrThrow(pem, { kind: 'ecdsa', curve: 'P-256' });
|
|
389
|
-
* const publicKey = await derivePublicKey(privateKey);
|
|
390
|
-
* const spkiPem = await exportSpkiPem(publicKey);
|
|
391
|
-
* ```
|
|
392
|
-
*
|
|
393
|
-
* @see {@linkcode exportSpkiDer} for exporting the derived key
|
|
394
|
-
*/
|
|
369
|
+
* Derive the matching public key from an imported (or generated) private key.
|
|
370
|
+
*
|
|
371
|
+
* The `import*` functions that read a PKCS#8 / PKCS#1 / SEC 1 / JWK private key
|
|
372
|
+
* return a bare `CryptoKey` with only `sign` (or, for RSA-OAEP, `decrypt`)
|
|
373
|
+
* usage — there is no accompanying public handle. This bridges that gap: it
|
|
374
|
+
* exports the private key's JWK, strips the private components, and re-imports
|
|
375
|
+
* the public half with `verify` (RSA-OAEP: `encrypt`) usage, so callers can go
|
|
376
|
+
* straight to {@linkcode exportSpkiDer} / {@linkcode exportSpkiPem} (e.g. to
|
|
377
|
+
* rebuild a self-signed cert or distribute the public key when only the
|
|
378
|
+
* private key is on disk).
|
|
379
|
+
*
|
|
380
|
+
* Supports RSA (`n`/`e`), ECDSA (`x`/`y`), and Ed25519 (`x`). The derived key
|
|
381
|
+
* inherits the private key's algorithm parameters (hash, curve).
|
|
382
|
+
*
|
|
383
|
+
* @param privateKey - An extractable private `CryptoKey`
|
|
384
|
+
* @returns Extractable public `CryptoKey` with `verify` (RSA-OAEP: `encrypt`) usage
|
|
385
|
+
*
|
|
386
|
+
* @throws {Error} If the key is not a private key, is non-extractable, or uses
|
|
387
|
+
* an unsupported key type
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* const privateKey = await importPkcs8PemOrThrow(pem, { kind: 'ecdsa', curve: 'P-256' });
|
|
392
|
+
* const publicKey = await derivePublicKey(privateKey);
|
|
393
|
+
* const spkiPem = await exportSpkiPem(publicKey);
|
|
394
|
+
* ```
|
|
395
|
+
*
|
|
396
|
+
* @see {@linkcode exportSpkiDer} for exporting the derived key
|
|
397
|
+
*/
|
|
395
398
|
declare function derivePublicKey(privateKey: CryptoKey): Promise<CryptoKey>;
|
|
396
399
|
/**
|
|
397
|
-
* Export a key as raw base64 (no PEM headers).
|
|
398
|
-
*
|
|
399
|
-
* Returns SPKI-encoded base64 for public keys, PKCS#8-encoded base64 for private keys.
|
|
400
|
-
* Useful for compact storage or transmission where PEM overhead is undesirable.
|
|
401
|
-
*
|
|
402
|
-
* @throws {Error} If the key is a symmetric/secret key
|
|
403
|
-
*
|
|
404
|
-
* @see {@linkcode importSpkiBase64} for public key import
|
|
405
|
-
* @see {@linkcode importPkcs8Base64} for private key import
|
|
406
|
-
*/
|
|
400
|
+
* Export a key as raw base64 (no PEM headers).
|
|
401
|
+
*
|
|
402
|
+
* Returns SPKI-encoded base64 for public keys, PKCS#8-encoded base64 for private keys.
|
|
403
|
+
* Useful for compact storage or transmission where PEM overhead is undesirable.
|
|
404
|
+
*
|
|
405
|
+
* @throws {Error} If the key is a symmetric/secret key
|
|
406
|
+
*
|
|
407
|
+
* @see {@linkcode importSpkiBase64} for public key import
|
|
408
|
+
* @see {@linkcode importPkcs8Base64} for private key import
|
|
409
|
+
*/
|
|
407
410
|
declare function exportBinaryBase64(key: CryptoKey): Promise<string>;
|
|
408
411
|
/**
|
|
409
|
-
* Import a public key from DER-encoded SubjectPublicKeyInfo.
|
|
410
|
-
*
|
|
411
|
-
* When `algorithm` is omitted, the algorithm (and, for EC keys, the curve) is
|
|
412
|
-
* inferred from the SPKI's own AlgorithmIdentifier — useful for keys whose type
|
|
413
|
-
* isn't known ahead of time. Pass `algorithm` to additionally assert that the
|
|
414
|
-
* DER matches an expected algorithm.
|
|
415
|
-
*
|
|
416
|
-
* @param der - DER-encoded SubjectPublicKeyInfo bytes
|
|
417
|
-
* @param algorithm - Optional expected algorithm; must match key contents when given
|
|
418
|
-
* @returns Extractable CryptoKey with `verify` usage
|
|
419
|
-
*
|
|
420
|
-
* @throws {Error} If DER is malformed, encodes an unsupported algorithm, or doesn't match `algorithm`
|
|
421
|
-
*
|
|
422
|
-
* @see {@linkcode exportSpkiDer} for the inverse operation
|
|
423
|
-
* @see {@linkcode importSpkiPem} for PEM input
|
|
424
|
-
*/
|
|
412
|
+
* Import a public key from DER-encoded SubjectPublicKeyInfo.
|
|
413
|
+
*
|
|
414
|
+
* When `algorithm` is omitted, the algorithm (and, for EC keys, the curve) is
|
|
415
|
+
* inferred from the SPKI's own AlgorithmIdentifier — useful for keys whose type
|
|
416
|
+
* isn't known ahead of time. Pass `algorithm` to additionally assert that the
|
|
417
|
+
* DER matches an expected algorithm.
|
|
418
|
+
*
|
|
419
|
+
* @param der - DER-encoded SubjectPublicKeyInfo bytes
|
|
420
|
+
* @param algorithm - Optional expected algorithm; must match key contents when given
|
|
421
|
+
* @returns Extractable CryptoKey with `verify` usage
|
|
422
|
+
*
|
|
423
|
+
* @throws {Error} If DER is malformed, encodes an unsupported algorithm, or doesn't match `algorithm`
|
|
424
|
+
*
|
|
425
|
+
* @see {@linkcode exportSpkiDer} for the inverse operation
|
|
426
|
+
* @see {@linkcode importSpkiPem} for PEM input
|
|
427
|
+
*/
|
|
425
428
|
declare function importSpkiDerOrThrow(der: Uint8Array, algorithm?: PublicKeyImportInput): Promise<CryptoKey>;
|
|
426
429
|
/**
|
|
427
|
-
* Import a public key from DER-encoded SubjectPublicKeyInfo.
|
|
428
|
-
*
|
|
429
|
-
* @see `importSpkiDerOrThrow` for the throwing variant
|
|
430
|
-
*/
|
|
430
|
+
* Import a public key from DER-encoded SubjectPublicKeyInfo.
|
|
431
|
+
*
|
|
432
|
+
* @see `importSpkiDerOrThrow` for the throwing variant
|
|
433
|
+
*/
|
|
431
434
|
declare function importSpkiDer(der: Uint8Array, algorithm?: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
432
435
|
/**
|
|
433
|
-
* Import a public key from PEM-encoded SubjectPublicKeyInfo.
|
|
434
|
-
*
|
|
435
|
-
* @example
|
|
436
|
-
* ```ts
|
|
437
|
-
* const pem = `-----BEGIN PUBLIC KEY-----
|
|
438
|
-
* MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE...
|
|
439
|
-
* -----END PUBLIC KEY-----`;
|
|
440
|
-
* const key = await importSpkiPemOrThrow(pem, { kind: 'ecdsa', curve: 'P-256' });
|
|
441
|
-
* ```
|
|
442
|
-
*
|
|
443
|
-
* @see {@linkcode exportSpkiPem} for the inverse operation
|
|
444
|
-
*/
|
|
436
|
+
* Import a public key from PEM-encoded SubjectPublicKeyInfo.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```ts
|
|
440
|
+
* const pem = `-----BEGIN PUBLIC KEY-----
|
|
441
|
+
* MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE...
|
|
442
|
+
* -----END PUBLIC KEY-----`;
|
|
443
|
+
* const key = await importSpkiPemOrThrow(pem, { kind: 'ecdsa', curve: 'P-256' });
|
|
444
|
+
* ```
|
|
445
|
+
*
|
|
446
|
+
* @see {@linkcode exportSpkiPem} for the inverse operation
|
|
447
|
+
*/
|
|
445
448
|
declare function importSpkiPemOrThrow(pem: string, algorithm?: PublicKeyImportInput): Promise<CryptoKey>;
|
|
446
449
|
/**
|
|
447
|
-
* Import a public key from PEM-encoded SubjectPublicKeyInfo.
|
|
448
|
-
*
|
|
449
|
-
* @see `importSpkiPemOrThrow` for the throwing variant
|
|
450
|
-
*/
|
|
450
|
+
* Import a public key from PEM-encoded SubjectPublicKeyInfo.
|
|
451
|
+
*
|
|
452
|
+
* @see `importSpkiPemOrThrow` for the throwing variant
|
|
453
|
+
*/
|
|
451
454
|
declare function importSpkiPem(pem: string, algorithm?: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
452
455
|
/**
|
|
453
|
-
* Import a public key from base64-encoded SubjectPublicKeyInfo (no PEM headers).
|
|
454
|
-
*
|
|
455
|
-
* @see {@linkcode exportBinaryBase64} for the inverse operation
|
|
456
|
-
* @see {@linkcode importSpkiPem} for PEM input with headers
|
|
457
|
-
*/
|
|
456
|
+
* Import a public key from base64-encoded SubjectPublicKeyInfo (no PEM headers).
|
|
457
|
+
*
|
|
458
|
+
* @see {@linkcode exportBinaryBase64} for the inverse operation
|
|
459
|
+
* @see {@linkcode importSpkiPem} for PEM input with headers
|
|
460
|
+
*/
|
|
458
461
|
declare function importSpkiBase64OrThrow(base64: string, algorithm?: PublicKeyImportInput): Promise<CryptoKey>;
|
|
459
462
|
/**
|
|
460
|
-
* Import a public key from base64-encoded SubjectPublicKeyInfo (no PEM headers).
|
|
461
|
-
*
|
|
462
|
-
* @see `importSpkiBase64OrThrow` for the throwing variant
|
|
463
|
-
*/
|
|
463
|
+
* Import a public key from base64-encoded SubjectPublicKeyInfo (no PEM headers).
|
|
464
|
+
*
|
|
465
|
+
* @see `importSpkiBase64OrThrow` for the throwing variant
|
|
466
|
+
*/
|
|
464
467
|
declare function importSpkiBase64(base64: string, algorithm?: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
465
468
|
/**
|
|
466
|
-
* Import a private key from DER-encoded PKCS#8 PrivateKeyInfo.
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
* @
|
|
475
|
-
* @
|
|
476
|
-
*
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
*
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
* @
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
* @
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
* @
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
|
|
469
|
+
* Import a private key from DER-encoded PKCS#8 PrivateKeyInfo.
|
|
470
|
+
*
|
|
471
|
+
* When `algorithm` is omitted, the algorithm (and, for EC keys, the curve) is
|
|
472
|
+
* inferred from the PrivateKeyInfo's own `privateKeyAlgorithm` — useful for
|
|
473
|
+
* keys whose type isn't known ahead of time. Pass `algorithm` to additionally
|
|
474
|
+
* assert that the DER matches an expected algorithm.
|
|
475
|
+
*
|
|
476
|
+
* @param der - DER-encoded PKCS#8 PrivateKeyInfo bytes
|
|
477
|
+
* @param algorithm - Optional expected algorithm; must match key contents when given
|
|
478
|
+
* @returns Extractable CryptoKey with `sign` usage
|
|
479
|
+
*
|
|
480
|
+
* @throws {Error} If DER is malformed, encodes an unsupported algorithm, or doesn't match `algorithm`
|
|
481
|
+
*
|
|
482
|
+
* @see {@linkcode exportPkcs8Der} for the inverse operation
|
|
483
|
+
* @see {@linkcode importPkcs8Pem} for PEM input
|
|
484
|
+
* @see {@linkcode importEncryptedPkcs8Der} for encrypted PKCS#8
|
|
485
|
+
*/
|
|
486
|
+
declare function importPkcs8DerOrThrow(der: Uint8Array, algorithm?: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
487
|
+
/**
|
|
488
|
+
* Import a private key from DER-encoded PKCS#8 PrivateKeyInfo.
|
|
489
|
+
*
|
|
490
|
+
* @see `importPkcs8DerOrThrow` for the throwing variant
|
|
491
|
+
*/
|
|
492
|
+
declare function importPkcs8Der(der: Uint8Array, algorithm?: PrivateKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
493
|
+
/**
|
|
494
|
+
* Import a private key from PEM-encoded PKCS#8 PrivateKeyInfo.
|
|
495
|
+
*
|
|
496
|
+
* When `algorithm` is omitted, it is inferred from the key's own
|
|
497
|
+
* `privateKeyAlgorithm` (see {@linkcode importPkcs8DerOrThrow}).
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* ```ts
|
|
501
|
+
* const key = await importPkcs8PemOrThrow(pemString, { kind: 'ecdsa', curve: 'P-256' });
|
|
502
|
+
* const inferred = await importPkcs8PemOrThrow(pemString);
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
declare function importPkcs8PemOrThrow(pem: string, algorithm?: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
506
|
+
/**
|
|
507
|
+
* Import a private key from PEM-encoded PKCS#8 PrivateKeyInfo.
|
|
508
|
+
*
|
|
509
|
+
* @see `importPkcs8PemOrThrow` for the throwing variant
|
|
510
|
+
*/
|
|
511
|
+
declare function importPkcs8Pem(pem: string, algorithm?: PrivateKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
512
|
+
/**
|
|
513
|
+
* Import a private key from DER-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
514
|
+
*
|
|
515
|
+
* Decrypts the PBES2 envelope using the provided password, then imports the key.
|
|
516
|
+
*
|
|
517
|
+
* When `algorithm` is omitted, it is inferred from the decrypted key's own
|
|
518
|
+
* `privateKeyAlgorithm` (see {@linkcode importPkcs8DerOrThrow}).
|
|
519
|
+
*
|
|
520
|
+
* @param der - DER-encoded EncryptedPrivateKeyInfo bytes
|
|
521
|
+
* @param password - Decryption password
|
|
522
|
+
* @param algorithm - Optional expected algorithm; must match decrypted key when given
|
|
523
|
+
*
|
|
524
|
+
* @throws {Error} If DER is malformed, password is wrong, or algorithm doesn't match
|
|
525
|
+
*
|
|
526
|
+
* @see {@linkcode exportEncryptedPkcs8Der} for the inverse operation
|
|
527
|
+
*/
|
|
528
|
+
declare function importEncryptedPkcs8DerOrThrow(der: Uint8Array, password: string, algorithm?: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
529
|
+
/**
|
|
530
|
+
* Import a private key from DER-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
531
|
+
*
|
|
532
|
+
* @see `importEncryptedPkcs8DerOrThrow` for the throwing variant
|
|
533
|
+
*/
|
|
534
|
+
declare function importEncryptedPkcs8Der(der: Uint8Array, password: string, algorithm?: PrivateKeyImportInput): Promise<ImportEncryptedKeyResult<CryptoKey>>;
|
|
535
|
+
/**
|
|
536
|
+
* Import a private key from PEM-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
537
|
+
*
|
|
538
|
+
* When `algorithm` is omitted, it is inferred from the decrypted key's own
|
|
539
|
+
* `privateKeyAlgorithm` (see {@linkcode importPkcs8DerOrThrow}).
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```ts
|
|
543
|
+
* const key = await importEncryptedPkcs8PemOrThrow(pem, 'secret', { kind: 'rsa' });
|
|
544
|
+
* const inferred = await importEncryptedPkcs8PemOrThrow(pem, 'secret');
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
declare function importEncryptedPkcs8PemOrThrow(pem: string, password: string, algorithm?: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
548
|
+
/**
|
|
549
|
+
* Import a private key from PEM-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
550
|
+
*
|
|
551
|
+
* @see `importEncryptedPkcs8PemOrThrow` for the throwing variant
|
|
552
|
+
*/
|
|
553
|
+
declare function importEncryptedPkcs8Pem(pem: string, password: string, algorithm?: PrivateKeyImportInput): Promise<ImportEncryptedKeyResult<CryptoKey>>;
|
|
554
|
+
/**
|
|
555
|
+
* Import an RSA private key from DER-encoded PKCS#1 RSAPrivateKey.
|
|
556
|
+
*
|
|
557
|
+
* PKCS#1 is the legacy RSA-only format. Internally converts to PKCS#8 for import.
|
|
558
|
+
*
|
|
559
|
+
* @see {@linkcode exportPkcs1Der} for the inverse operation
|
|
560
|
+
* @see {@linkcode importPkcs1Pem} for PEM input
|
|
561
|
+
*/
|
|
543
562
|
declare function importPkcs1DerOrThrow(der: Uint8Array, algorithm?: ImportRsaKeyInput): Promise<CryptoKey>;
|
|
544
563
|
/**
|
|
545
|
-
* Import an RSA private key from DER-encoded PKCS#1 RSAPrivateKey.
|
|
546
|
-
*
|
|
547
|
-
* @see `importPkcs1DerOrThrow` for the throwing variant
|
|
548
|
-
*/
|
|
564
|
+
* Import an RSA private key from DER-encoded PKCS#1 RSAPrivateKey.
|
|
565
|
+
*
|
|
566
|
+
* @see `importPkcs1DerOrThrow` for the throwing variant
|
|
567
|
+
*/
|
|
549
568
|
declare function importPkcs1Der(der: Uint8Array, algorithm?: ImportRsaKeyInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
550
569
|
/**
|
|
551
|
-
* Import an RSA private key from PEM-encoded PKCS#1 RSAPrivateKey.
|
|
552
|
-
*
|
|
553
|
-
* Expects the `-----BEGIN RSA PRIVATE KEY-----` PEM label.
|
|
554
|
-
*
|
|
555
|
-
* @see {@linkcode exportPkcs1Pem} for the inverse operation
|
|
556
|
-
* @see {@linkcode importEncryptedPkcs1Pem} for encrypted PEM
|
|
557
|
-
*/
|
|
570
|
+
* Import an RSA private key from PEM-encoded PKCS#1 RSAPrivateKey.
|
|
571
|
+
*
|
|
572
|
+
* Expects the `-----BEGIN RSA PRIVATE KEY-----` PEM label.
|
|
573
|
+
*
|
|
574
|
+
* @see {@linkcode exportPkcs1Pem} for the inverse operation
|
|
575
|
+
* @see {@linkcode importEncryptedPkcs1Pem} for encrypted PEM
|
|
576
|
+
*/
|
|
558
577
|
declare function importPkcs1PemOrThrow(pem: string, algorithm?: ImportRsaKeyInput): Promise<CryptoKey>;
|
|
559
578
|
/**
|
|
560
|
-
* Import an RSA private key from PEM-encoded PKCS#1 RSAPrivateKey.
|
|
561
|
-
*
|
|
562
|
-
* @see `importPkcs1PemOrThrow` for the throwing variant
|
|
563
|
-
*/
|
|
579
|
+
* Import an RSA private key from PEM-encoded PKCS#1 RSAPrivateKey.
|
|
580
|
+
*
|
|
581
|
+
* @see `importPkcs1PemOrThrow` for the throwing variant
|
|
582
|
+
*/
|
|
564
583
|
declare function importPkcs1Pem(pem: string, algorithm?: ImportRsaKeyInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
565
584
|
/**
|
|
566
|
-
* Import an RSA private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
567
|
-
*
|
|
568
|
-
* Decrypts OpenSSL's traditional PEM encryption format.
|
|
569
|
-
*
|
|
570
|
-
* @see {@linkcode exportEncryptedPkcs1Pem} for the inverse operation
|
|
571
|
-
* @see {@linkcode importEncryptedPkcs8Pem} for modern PBES2 encryption
|
|
572
|
-
*/
|
|
585
|
+
* Import an RSA private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
586
|
+
*
|
|
587
|
+
* Decrypts OpenSSL's traditional PEM encryption format.
|
|
588
|
+
*
|
|
589
|
+
* @see {@linkcode exportEncryptedPkcs1Pem} for the inverse operation
|
|
590
|
+
* @see {@linkcode importEncryptedPkcs8Pem} for modern PBES2 encryption
|
|
591
|
+
*/
|
|
573
592
|
declare function importEncryptedPkcs1PemOrThrow(pem: string, password: string, algorithm?: ImportRsaKeyInput): Promise<CryptoKey>;
|
|
574
593
|
/**
|
|
575
|
-
* Import an RSA private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
576
|
-
*
|
|
577
|
-
* @see `importEncryptedPkcs1PemOrThrow` for the throwing variant
|
|
578
|
-
*/
|
|
594
|
+
* Import an RSA private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
595
|
+
*
|
|
596
|
+
* @see `importEncryptedPkcs1PemOrThrow` for the throwing variant
|
|
597
|
+
*/
|
|
579
598
|
declare function importEncryptedPkcs1Pem(pem: string, password: string, algorithm?: ImportRsaKeyInput): Promise<ImportEncryptedKeyResult<CryptoKey>>;
|
|
580
599
|
/**
|
|
581
|
-
* Import a private key from base64-encoded PKCS#8 PrivateKeyInfo (no PEM headers).
|
|
582
|
-
*
|
|
583
|
-
* @see {@linkcode exportBinaryBase64} for the inverse operation
|
|
584
|
-
* @see {@linkcode importPkcs8Pem} for PEM input with headers
|
|
585
|
-
*/
|
|
586
|
-
declare function importPkcs8Base64OrThrow(base64: string, algorithm
|
|
587
|
-
/**
|
|
588
|
-
* Import a private key from base64-encoded PKCS#8 PrivateKeyInfo (no PEM headers).
|
|
589
|
-
*
|
|
590
|
-
* @see `importPkcs8Base64OrThrow` for the throwing variant
|
|
591
|
-
*/
|
|
592
|
-
declare function importPkcs8Base64(base64: string, algorithm
|
|
593
|
-
/**
|
|
594
|
-
* Import an EC private key from DER-encoded SEC 1 ECPrivateKey.
|
|
595
|
-
*
|
|
596
|
-
* SEC 1 is the legacy EC-only format. Internally converts to PKCS#8 for import.
|
|
597
|
-
* When the ECPrivateKey carries the optional RFC 5915 `parameters [0]` field
|
|
598
|
-
* (OpenSSL always writes it), its named-curve OID must match `algorithm.curve`;
|
|
599
|
-
* when the field is absent, the caller-supplied curve is trusted.
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
* @
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
*
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
*
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
* @see
|
|
626
|
-
*/
|
|
627
|
-
declare function
|
|
628
|
-
/**
|
|
629
|
-
* Import an EC private key from
|
|
630
|
-
*
|
|
631
|
-
*
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
*
|
|
639
|
-
*
|
|
640
|
-
* @see
|
|
641
|
-
*/
|
|
642
|
-
declare function
|
|
643
|
-
/**
|
|
644
|
-
* Import
|
|
645
|
-
*
|
|
646
|
-
* @
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
* @
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
*
|
|
681
|
-
*
|
|
682
|
-
* @
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
* )
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
* @
|
|
710
|
-
* @
|
|
711
|
-
|
|
600
|
+
* Import a private key from base64-encoded PKCS#8 PrivateKeyInfo (no PEM headers).
|
|
601
|
+
*
|
|
602
|
+
* @see {@linkcode exportBinaryBase64} for the inverse operation
|
|
603
|
+
* @see {@linkcode importPkcs8Pem} for PEM input with headers
|
|
604
|
+
*/
|
|
605
|
+
declare function importPkcs8Base64OrThrow(base64: string, algorithm?: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
606
|
+
/**
|
|
607
|
+
* Import a private key from base64-encoded PKCS#8 PrivateKeyInfo (no PEM headers).
|
|
608
|
+
*
|
|
609
|
+
* @see `importPkcs8Base64OrThrow` for the throwing variant
|
|
610
|
+
*/
|
|
611
|
+
declare function importPkcs8Base64(base64: string, algorithm?: PrivateKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
612
|
+
/**
|
|
613
|
+
* Import an EC private key from DER-encoded SEC 1 ECPrivateKey.
|
|
614
|
+
*
|
|
615
|
+
* SEC 1 is the legacy EC-only format. Internally converts to PKCS#8 for import.
|
|
616
|
+
* When the ECPrivateKey carries the optional RFC 5915 `parameters [0]` field
|
|
617
|
+
* (OpenSSL always writes it), its named-curve OID must match `algorithm.curve`;
|
|
618
|
+
* when the field is absent, the caller-supplied curve is trusted.
|
|
619
|
+
*
|
|
620
|
+
* When `algorithm` is omitted, the curve is inferred from the embedded
|
|
621
|
+
* `parameters [0]` field; a key without a supported named curve then fails.
|
|
622
|
+
*
|
|
623
|
+
* @throws {Error} If DER is not an ECPrivateKey, its embedded curve doesn't
|
|
624
|
+
* match `algorithm`, or no curve is available (neither embedded nor supplied)
|
|
625
|
+
*
|
|
626
|
+
* @see {@linkcode exportSec1Der} for the inverse operation
|
|
627
|
+
* @see {@linkcode importSec1Pem} for PEM input
|
|
628
|
+
*/
|
|
629
|
+
declare function importSec1DerOrThrow(der: Uint8Array, algorithm?: ImportEcKeyInput): Promise<CryptoKey>;
|
|
630
|
+
/**
|
|
631
|
+
* Import an EC private key from DER-encoded SEC 1 ECPrivateKey.
|
|
632
|
+
*
|
|
633
|
+
* @see `importSec1DerOrThrow` for the throwing variant
|
|
634
|
+
*/
|
|
635
|
+
declare function importSec1Der(der: Uint8Array, algorithm?: ImportEcKeyInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
636
|
+
/**
|
|
637
|
+
* Import an EC private key from PEM-encoded SEC 1 ECPrivateKey.
|
|
638
|
+
*
|
|
639
|
+
* Expects the `-----BEGIN EC PRIVATE KEY-----` PEM label. When `algorithm` is
|
|
640
|
+
* omitted, the curve is inferred from the embedded `parameters [0]` field
|
|
641
|
+
* (see {@linkcode importSec1DerOrThrow}).
|
|
642
|
+
*
|
|
643
|
+
* @see {@linkcode exportSec1Pem} for the inverse operation
|
|
644
|
+
* @see {@linkcode importEncryptedSec1Pem} for encrypted PEM
|
|
645
|
+
*/
|
|
646
|
+
declare function importSec1PemOrThrow(pem: string, algorithm?: ImportEcKeyInput): Promise<CryptoKey>;
|
|
647
|
+
/**
|
|
648
|
+
* Import an EC private key from PEM-encoded SEC 1 ECPrivateKey.
|
|
649
|
+
*
|
|
650
|
+
* @see `importSec1PemOrThrow` for the throwing variant
|
|
651
|
+
*/
|
|
652
|
+
declare function importSec1Pem(pem: string, algorithm?: ImportEcKeyInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
653
|
+
/**
|
|
654
|
+
* Import an EC private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (SEC 1).
|
|
655
|
+
*
|
|
656
|
+
* Decrypts OpenSSL's traditional PEM encryption format.
|
|
657
|
+
*
|
|
658
|
+
* @see {@linkcode exportEncryptedSec1Pem} for the inverse operation
|
|
659
|
+
* @see {@linkcode importEncryptedPkcs8Pem} for modern PBES2 encryption
|
|
660
|
+
*/
|
|
661
|
+
declare function importEncryptedSec1PemOrThrow(pem: string, password: string, algorithm?: ImportEcKeyInput): Promise<CryptoKey>;
|
|
662
|
+
/**
|
|
663
|
+
* Import an EC private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (SEC 1).
|
|
664
|
+
*
|
|
665
|
+
* @see `importEncryptedSec1PemOrThrow` for the throwing variant
|
|
666
|
+
*/
|
|
667
|
+
declare function importEncryptedSec1Pem(pem: string, password: string, algorithm?: ImportEcKeyInput): Promise<ImportEncryptedKeyResult<CryptoKey>>;
|
|
668
|
+
/**
|
|
669
|
+
* Import a public verification key from a JSON Web Key.
|
|
670
|
+
*
|
|
671
|
+
* When `algorithm` is omitted, it is inferred from the JWK's own `kty`, `crv`,
|
|
672
|
+
* and `alg` members (e.g. `PS256` → RSA-PSS/SHA-256, `RSA-OAEP-256` →
|
|
673
|
+
* RSA-OAEP/SHA-256; an RSA JWK without `alg` defaults to PKCS#1 v1.5 with
|
|
674
|
+
* SHA-256). Pass `algorithm` to additionally assert an expected algorithm.
|
|
675
|
+
*
|
|
676
|
+
* @param jwk - JSON Web Key object with public key components
|
|
677
|
+
* @param algorithm - Optional expected algorithm; must match JWK's `kty` and `crv` when given
|
|
678
|
+
* @returns Extractable CryptoKey with `verify` usage
|
|
679
|
+
*
|
|
680
|
+
* @throws {Error} If JWK is malformed, encodes an unsupported algorithm, or doesn't match `algorithm`
|
|
681
|
+
*
|
|
682
|
+
* @see {@linkcode exportPublicJwk} for the inverse operation
|
|
683
|
+
*/
|
|
684
|
+
declare function importPublicJwkOrThrow(jwk: JsonWebKey, algorithm?: PublicKeyImportInput): Promise<CryptoKey>;
|
|
685
|
+
/**
|
|
686
|
+
* Import a public verification key from a JSON Web Key.
|
|
687
|
+
*
|
|
688
|
+
* @see `importPublicJwkOrThrow` for the throwing variant
|
|
689
|
+
*/
|
|
690
|
+
declare function importPublicJwk(jwk: JsonWebKey, algorithm?: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
691
|
+
/**
|
|
692
|
+
* Import a private signing key from a JSON Web Key.
|
|
693
|
+
*
|
|
694
|
+
* When `algorithm` is omitted, it is inferred from the JWK's own `kty`, `crv`,
|
|
695
|
+
* and `alg` members (see {@linkcode importPublicJwkOrThrow}).
|
|
696
|
+
*
|
|
697
|
+
* @param jwk - JSON Web Key object with private key components
|
|
698
|
+
* @param algorithm - Optional expected algorithm; must match JWK's `kty` and `crv` when given
|
|
699
|
+
* @returns Extractable CryptoKey with `sign` usage
|
|
700
|
+
*
|
|
701
|
+
* @throws {Error} If JWK is malformed, lacks private key material, encodes an
|
|
702
|
+
* unsupported algorithm, or doesn't match `algorithm`
|
|
703
|
+
*
|
|
704
|
+
* @example
|
|
705
|
+
* ```ts
|
|
706
|
+
* const jwk = { kty: 'EC', crv: 'P-256', x: '...', y: '...', d: '...' };
|
|
707
|
+
* const key = await importPrivateJwkOrThrow(jwk, { kind: 'ecdsa', curve: 'P-256' });
|
|
708
|
+
* const inferred = await importPrivateJwkOrThrow(jwk);
|
|
709
|
+
* ```
|
|
710
|
+
*
|
|
711
|
+
* @see {@linkcode exportPrivateJwk} for the inverse operation
|
|
712
|
+
*/
|
|
713
|
+
declare function importPrivateJwkOrThrow(jwk: JsonWebKey, algorithm?: PrivateKeyImportInput): Promise<CryptoKey>;
|
|
714
|
+
/**
|
|
715
|
+
* Import a private signing key from a JSON Web Key.
|
|
716
|
+
*
|
|
717
|
+
* @see `importPrivateJwkOrThrow` for the throwing variant
|
|
718
|
+
*/
|
|
719
|
+
declare function importPrivateJwk(jwk: JsonWebKey, algorithm?: PrivateKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
720
|
+
/**
|
|
721
|
+
* Encrypt a small message with an RSA-OAEP public key.
|
|
722
|
+
*
|
|
723
|
+
* The key must have been generated or imported with `{ kind: 'rsa', scheme: 'oaep' }`.
|
|
724
|
+
* RSA-OAEP encrypts at most modulus bytes − 2 × hash bytes − 2 per call
|
|
725
|
+
* (190 bytes for a 2048-bit key with SHA-256) — encrypt a symmetric key, not
|
|
726
|
+
* bulk data.
|
|
727
|
+
*
|
|
728
|
+
* @param publicKey - RSA-OAEP public `CryptoKey` with `encrypt` usage
|
|
729
|
+
* @param plaintext - Message bytes, at most the OAEP capacity of the key
|
|
730
|
+
* @param options - Optional OAEP label bound to the ciphertext
|
|
731
|
+
*
|
|
732
|
+
* @throws {Error} If the key is not an RSA-OAEP public encryption key, or the
|
|
733
|
+
* plaintext exceeds the key's OAEP capacity
|
|
734
|
+
*
|
|
735
|
+
* @example
|
|
736
|
+
* ```ts
|
|
737
|
+
* const keys = await generateKeyPair({ kind: 'rsa', scheme: 'oaep' });
|
|
738
|
+
* const ciphertext = await encryptRsaOaepOrThrow(
|
|
739
|
+
* keys.publicKey,
|
|
740
|
+
* new TextEncoder().encode('session key'),
|
|
741
|
+
* );
|
|
742
|
+
* ```
|
|
743
|
+
*
|
|
744
|
+
* @see {@linkcode decryptRsaOaepOrThrow} for the inverse operation
|
|
745
|
+
* @see `encryptRsaOaep` for the Result-returning variant
|
|
746
|
+
*/
|
|
712
747
|
declare function encryptRsaOaepOrThrow(publicKey: CryptoKey, plaintext: Uint8Array, options?: RsaOaepOptions): Promise<Uint8Array>;
|
|
713
748
|
/**
|
|
714
|
-
* Encrypt a small message with an RSA-OAEP public key.
|
|
715
|
-
*
|
|
716
|
-
* @example
|
|
717
|
-
* ```ts
|
|
718
|
-
* const keys = await generateKeyPair({ kind: 'rsa', scheme: 'oaep' });
|
|
719
|
-
* const encrypted = await encryptRsaOaep(keys.publicKey, plaintext);
|
|
720
|
-
* if (!encrypted.ok) {
|
|
721
|
-
* // encrypted.code: 'invalid_key' | 'message_too_long'
|
|
722
|
-
* throw new Error(encrypted.message);
|
|
723
|
-
* }
|
|
724
|
-
* const ciphertext = encrypted.value;
|
|
725
|
-
* ```
|
|
726
|
-
*
|
|
727
|
-
* @see `encryptRsaOaepOrThrow` for the throwing variant
|
|
728
|
-
*/
|
|
749
|
+
* Encrypt a small message with an RSA-OAEP public key.
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* ```ts
|
|
753
|
+
* const keys = await generateKeyPair({ kind: 'rsa', scheme: 'oaep' });
|
|
754
|
+
* const encrypted = await encryptRsaOaep(keys.publicKey, plaintext);
|
|
755
|
+
* if (!encrypted.ok) {
|
|
756
|
+
* // encrypted.code: 'invalid_key' | 'message_too_long'
|
|
757
|
+
* throw new Error(encrypted.message);
|
|
758
|
+
* }
|
|
759
|
+
* const ciphertext = encrypted.value;
|
|
760
|
+
* ```
|
|
761
|
+
*
|
|
762
|
+
* @see `encryptRsaOaepOrThrow` for the throwing variant
|
|
763
|
+
*/
|
|
729
764
|
declare function encryptRsaOaep(publicKey: CryptoKey, plaintext: Uint8Array, options?: RsaOaepOptions): Promise<EncryptRsaOaepResult>;
|
|
730
765
|
/**
|
|
731
|
-
* Decrypt an RSA-OAEP ciphertext with the matching private key.
|
|
732
|
-
*
|
|
733
|
-
* The key must have been generated or imported with `{ kind: 'rsa', scheme: 'oaep' }`,
|
|
734
|
-
* and `options.label` must repeat the label used at encryption time (if any).
|
|
735
|
-
*
|
|
736
|
-
* @param privateKey - RSA-OAEP private `CryptoKey` with `decrypt` usage
|
|
737
|
-
* @param ciphertext - Ciphertext produced by {@linkcode encryptRsaOaep} (or any RSA-OAEP encryptor)
|
|
738
|
-
* @param options - OAEP label matching the one bound at encryption
|
|
739
|
-
*
|
|
740
|
-
* @throws {Error} If the key is not an RSA-OAEP private decryption key, or
|
|
741
|
-
* decryption fails — wrong key, wrong label, or corrupted ciphertext (OAEP
|
|
742
|
-
* deliberately does not reveal which)
|
|
743
|
-
*
|
|
744
|
-
* @example
|
|
745
|
-
* ```ts
|
|
746
|
-
* const plaintext = await decryptRsaOaepOrThrow(keys.privateKey, ciphertext);
|
|
747
|
-
* ```
|
|
748
|
-
*
|
|
749
|
-
* @see {@linkcode encryptRsaOaepOrThrow} for the inverse operation
|
|
750
|
-
* @see `decryptRsaOaep` for the Result-returning variant
|
|
751
|
-
*/
|
|
766
|
+
* Decrypt an RSA-OAEP ciphertext with the matching private key.
|
|
767
|
+
*
|
|
768
|
+
* The key must have been generated or imported with `{ kind: 'rsa', scheme: 'oaep' }`,
|
|
769
|
+
* and `options.label` must repeat the label used at encryption time (if any).
|
|
770
|
+
*
|
|
771
|
+
* @param privateKey - RSA-OAEP private `CryptoKey` with `decrypt` usage
|
|
772
|
+
* @param ciphertext - Ciphertext produced by {@linkcode encryptRsaOaep} (or any RSA-OAEP encryptor)
|
|
773
|
+
* @param options - OAEP label matching the one bound at encryption
|
|
774
|
+
*
|
|
775
|
+
* @throws {Error} If the key is not an RSA-OAEP private decryption key, or
|
|
776
|
+
* decryption fails — wrong key, wrong label, or corrupted ciphertext (OAEP
|
|
777
|
+
* deliberately does not reveal which)
|
|
778
|
+
*
|
|
779
|
+
* @example
|
|
780
|
+
* ```ts
|
|
781
|
+
* const plaintext = await decryptRsaOaepOrThrow(keys.privateKey, ciphertext);
|
|
782
|
+
* ```
|
|
783
|
+
*
|
|
784
|
+
* @see {@linkcode encryptRsaOaepOrThrow} for the inverse operation
|
|
785
|
+
* @see `decryptRsaOaep` for the Result-returning variant
|
|
786
|
+
*/
|
|
752
787
|
declare function decryptRsaOaepOrThrow(privateKey: CryptoKey, ciphertext: Uint8Array, options?: RsaOaepOptions): Promise<Uint8Array>;
|
|
753
788
|
/**
|
|
754
|
-
* Decrypt an RSA-OAEP ciphertext with the matching private key.
|
|
755
|
-
*
|
|
756
|
-
* @example
|
|
757
|
-
* ```ts
|
|
758
|
-
* const decrypted = await decryptRsaOaep(keys.privateKey, ciphertext);
|
|
759
|
-
* if (!decrypted.ok) {
|
|
760
|
-
* // decrypted.code: 'invalid_key' | 'decryption_failed'
|
|
761
|
-
* throw new Error(decrypted.message);
|
|
762
|
-
* }
|
|
763
|
-
* const plaintext = decrypted.value;
|
|
764
|
-
* ```
|
|
765
|
-
*
|
|
766
|
-
* @see `decryptRsaOaepOrThrow` for the throwing variant
|
|
767
|
-
*/
|
|
789
|
+
* Decrypt an RSA-OAEP ciphertext with the matching private key.
|
|
790
|
+
*
|
|
791
|
+
* @example
|
|
792
|
+
* ```ts
|
|
793
|
+
* const decrypted = await decryptRsaOaep(keys.privateKey, ciphertext);
|
|
794
|
+
* if (!decrypted.ok) {
|
|
795
|
+
* // decrypted.code: 'invalid_key' | 'decryption_failed'
|
|
796
|
+
* throw new Error(decrypted.message);
|
|
797
|
+
* }
|
|
798
|
+
* const plaintext = decrypted.value;
|
|
799
|
+
* ```
|
|
800
|
+
*
|
|
801
|
+
* @see `decryptRsaOaepOrThrow` for the throwing variant
|
|
802
|
+
*/
|
|
768
803
|
declare function decryptRsaOaep(privateKey: CryptoKey, ciphertext: Uint8Array, options?: RsaOaepOptions): Promise<DecryptRsaOaepResult>;
|
|
769
804
|
//#endregion
|
|
770
|
-
export { DecryptRsaOaepErrorCode, DecryptRsaOaepFailure, DecryptRsaOaepResult, EcKeyAlgorithmInput, EcNamedCurve, Ed25519KeyAlgorithmInput, EncryptRsaOaepErrorCode, EncryptRsaOaepFailure, EncryptRsaOaepResult, EncryptedPkcs8Options, ImportEcKeyInput, ImportEd25519KeyInput, ImportEncryptedKeyErrorCode, ImportEncryptedKeyFailure, ImportEncryptedKeyResult, ImportKeyErrorCode, ImportKeyFailure, ImportKeyResult, ImportRsaKeyInput, KeyAlgorithmInput, KeyPairMaterial, LegacyPemEncryptionOptions, PrivateKeyImportInput, PublicKeyImportInput, RsaHash, RsaKeyAlgorithmInput, RsaOaepOptions, RsaScheme, RsaSignatureScheme, decryptRsaOaep, decryptRsaOaepOrThrow, derivePublicKey, encryptRsaOaep, encryptRsaOaepOrThrow, 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 };
|
|
805
|
+
export { DecryptRsaOaepErrorCode, DecryptRsaOaepFailure, DecryptRsaOaepResult, EcKeyAlgorithmInput, EcNamedCurve, Ed25519KeyAlgorithmInput, EncryptRsaOaepErrorCode, EncryptRsaOaepFailure, EncryptRsaOaepResult, EncryptedPkcs8Options, ImportEcKeyInput, ImportEd25519KeyInput, ImportEncryptedKeyErrorCode, ImportEncryptedKeyFailure, ImportEncryptedKeyResult, ImportKeyErrorCode, ImportKeyFailure, ImportKeyResult, ImportRsaKeyInput, KeyAlgorithmInput, KeyPairMaterial, LegacyPemEncryptionOptions, PrivateKeyImportInput, PublicKeyImportInput, RsaHash, RsaKeyAlgorithmInput, RsaOaepOptions, RsaScheme, RsaSignatureScheme, decryptRsaOaep, decryptRsaOaepOrThrow, derivePublicKey, encryptRsaOaep, encryptRsaOaepOrThrow, 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 };
|
|
806
|
+
//# sourceMappingURL=keys.d.ts.map
|