micro509 0.8.0 → 0.10.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 +4 -4
- package/dist/index.js +15 -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 +626 -447
- package/dist/keys/keys.js +652 -404
- package/dist/keys/keys.js.map +1 -0
- package/dist/keys.d.ts +2 -2
- 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 +581 -638
- 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/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 +185 -185
- package/dist/x509/parse.js +638 -676
- package/dist/x509/parse.js.map +1 -0
- package/dist/x509.js +6 -6
- package/package.json +79 -41
package/dist/keys/keys.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
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
|
-
type
|
|
6
|
+
type RsaSignatureScheme = "pkcs1-v1_5" | "pss";
|
|
7
|
+
/**
|
|
8
|
+
* RSA padding scheme: a signature scheme, or `'oaep'` for RSA-OAEP encryption
|
|
9
|
+
* keys (usable with {@linkcode encryptRsaOaep} / {@linkcode decryptRsaOaep}).
|
|
10
|
+
*/
|
|
11
|
+
type RsaScheme = RsaSignatureScheme | "oaep";
|
|
8
12
|
/** NIST elliptic curve for ECDSA keys. */
|
|
9
13
|
type EcNamedCurve = "P-256" | "P-384" | "P-521";
|
|
10
14
|
/** RSA variant of {@linkcode KeyAlgorithmInput}. */
|
|
@@ -15,7 +19,10 @@ interface RsaKeyAlgorithmInput {
|
|
|
15
19
|
readonly modulusLength?: 2048 | 3072 | 4096;
|
|
16
20
|
/** Hash algorithm for the key. Defaults to `'SHA-256'`. */
|
|
17
21
|
readonly hash?: RsaHash;
|
|
18
|
-
/**
|
|
22
|
+
/**
|
|
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
|
+
*/
|
|
19
26
|
readonly scheme?: RsaScheme;
|
|
20
27
|
}
|
|
21
28
|
/** ECDSA variant of {@linkcode KeyAlgorithmInput}. */
|
|
@@ -34,9 +41,9 @@ interface Ed25519KeyAlgorithmInput {
|
|
|
34
41
|
type KeyAlgorithmInput = RsaKeyAlgorithmInput | EcKeyAlgorithmInput | Ed25519KeyAlgorithmInput;
|
|
35
42
|
/** Key pair with convenience export helpers. Returned by {@linkcode generateKeyPair}. */
|
|
36
43
|
interface KeyPairMaterial {
|
|
37
|
-
/** The WebCrypto public key (extractable, `verify` usage). */
|
|
44
|
+
/** The WebCrypto public key (extractable, `verify` usage; `encrypt` for RSA-OAEP). */
|
|
38
45
|
readonly publicKey: CryptoKey;
|
|
39
|
-
/** The WebCrypto private key (extractable, `sign` usage). */
|
|
46
|
+
/** The WebCrypto private key (extractable, `sign` usage; `decrypt` for RSA-OAEP). */
|
|
40
47
|
readonly privateKey: CryptoKey;
|
|
41
48
|
/** Export the public key as DER-encoded SubjectPublicKeyInfo. */
|
|
42
49
|
exportSpkiDer(): Promise<Uint8Array>;
|
|
@@ -57,7 +64,10 @@ interface ImportRsaKeyInput {
|
|
|
57
64
|
readonly kind: "rsa";
|
|
58
65
|
/** Hash algorithm. Defaults to `'SHA-256'`. */
|
|
59
66
|
readonly hash?: RsaHash;
|
|
60
|
-
/**
|
|
67
|
+
/**
|
|
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
|
+
*/
|
|
61
71
|
readonly scheme?: RsaScheme;
|
|
62
72
|
}
|
|
63
73
|
/** ECDSA variant of {@linkcode PublicKeyImportInput} / {@linkcode PrivateKeyImportInput}. */
|
|
@@ -108,22 +118,22 @@ interface ImportKeyFailure extends Micro509Error<ImportKeyErrorCode> {
|
|
|
108
118
|
readonly ok: false;
|
|
109
119
|
}
|
|
110
120
|
/**
|
|
111
|
-
* Success-or-failure result returned by the public `import*` key functions.
|
|
112
|
-
*
|
|
113
|
-
* On failure, `code` is always `'malformed'`: structurally invalid input,
|
|
114
|
-
* algorithm mismatches, and wrong-password decryption failures all surface
|
|
115
|
-
* the same way (see the throwing `*OrThrow` variants for raw error messages).
|
|
116
|
-
*/
|
|
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
|
+
*/
|
|
117
127
|
type ImportKeyResult<T> = {
|
|
118
128
|
readonly ok: true;
|
|
119
129
|
readonly value: T;
|
|
120
130
|
} | ErrorResult<ImportKeyErrorCode, Record<never, never>, ImportKeyFailure>;
|
|
121
131
|
/**
|
|
122
|
-
* Machine-readable failure reason for the `importEncrypted*` key functions.
|
|
123
|
-
*
|
|
124
|
-
* Distinguishes a wrong decryption password (`'invalid_password'`) from
|
|
125
|
-
* structurally invalid input or algorithm mismatches (`'malformed'`).
|
|
126
|
-
*/
|
|
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
|
+
*/
|
|
127
137
|
type ImportEncryptedKeyErrorCode = "malformed" | "invalid_password";
|
|
128
138
|
/** Structured failure payload for encrypted key import. */
|
|
129
139
|
interface ImportEncryptedKeyFailure extends Micro509Error<ImportEncryptedKeyErrorCode> {
|
|
@@ -131,497 +141,666 @@ interface ImportEncryptedKeyFailure extends Micro509Error<ImportEncryptedKeyErro
|
|
|
131
141
|
readonly ok: false;
|
|
132
142
|
}
|
|
133
143
|
/**
|
|
134
|
-
* Success-or-failure result returned by the public `importEncrypted*` key functions.
|
|
135
|
-
*
|
|
136
|
-
* On failure, `code` is `'invalid_password'` when decryption failed (wrong
|
|
137
|
-
* password or corrupted ciphertext) and `'malformed'` for everything else.
|
|
138
|
-
*/
|
|
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
|
+
*/
|
|
139
149
|
type ImportEncryptedKeyResult<T> = {
|
|
140
150
|
readonly ok: true;
|
|
141
151
|
readonly value: T;
|
|
142
152
|
} | ErrorResult<ImportEncryptedKeyErrorCode, Record<never, never>, ImportEncryptedKeyFailure>;
|
|
153
|
+
/** Options shared by {@linkcode encryptRsaOaep} and {@linkcode decryptRsaOaep}. */
|
|
154
|
+
interface RsaOaepOptions {
|
|
155
|
+
/**
|
|
156
|
+
* Optional OAEP label bound to the ciphertext. Not encrypted, but decryption
|
|
157
|
+
* fails unless the exact same label is presented. Default: empty.
|
|
158
|
+
*/
|
|
159
|
+
readonly label?: Uint8Array;
|
|
160
|
+
}
|
|
143
161
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
*/
|
|
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
|
+
*/
|
|
168
|
+
type EncryptRsaOaepErrorCode = "invalid_key" | "message_too_long";
|
|
169
|
+
/** Structured failure payload for {@linkcode encryptRsaOaep}. */
|
|
170
|
+
interface EncryptRsaOaepFailure extends Micro509Error<EncryptRsaOaepErrorCode> {
|
|
171
|
+
/** Always `false` for failures. */
|
|
172
|
+
readonly ok: false;
|
|
173
|
+
}
|
|
174
|
+
/** Success-or-failure result returned by {@linkcode encryptRsaOaep}. */
|
|
175
|
+
type EncryptRsaOaepResult = {
|
|
176
|
+
readonly ok: true;
|
|
177
|
+
readonly value: Uint8Array;
|
|
178
|
+
} | ErrorResult<EncryptRsaOaepErrorCode, Record<never, never>, EncryptRsaOaepFailure>;
|
|
179
|
+
/**
|
|
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
|
+
*/
|
|
187
|
+
type DecryptRsaOaepErrorCode = "invalid_key" | "decryption_failed";
|
|
188
|
+
/** Structured failure payload for {@linkcode decryptRsaOaep}. */
|
|
189
|
+
interface DecryptRsaOaepFailure extends Micro509Error<DecryptRsaOaepErrorCode> {
|
|
190
|
+
/** Always `false` for failures. */
|
|
191
|
+
readonly ok: false;
|
|
192
|
+
}
|
|
193
|
+
/** Success-or-failure result returned by {@linkcode decryptRsaOaep}. */
|
|
194
|
+
type DecryptRsaOaepResult = {
|
|
195
|
+
readonly ok: true;
|
|
196
|
+
readonly value: Uint8Array;
|
|
197
|
+
} | ErrorResult<DecryptRsaOaepErrorCode, Record<never, never>, DecryptRsaOaepFailure>;
|
|
198
|
+
/**
|
|
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
|
+
*/
|
|
157
214
|
declare function generateKeyPair(algorithm?: KeyAlgorithmInput): Promise<KeyPairMaterial>;
|
|
158
215
|
/**
|
|
159
|
-
* Export a public key as DER-encoded SubjectPublicKeyInfo.
|
|
160
|
-
*
|
|
161
|
-
* @see {@linkcode importSpkiDer} for the inverse operation
|
|
162
|
-
* @see {@linkcode exportSpkiPem} for PEM output
|
|
163
|
-
*/
|
|
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
|
+
*/
|
|
164
221
|
declare function exportSpkiDer(publicKey: CryptoKey): Promise<Uint8Array>;
|
|
165
222
|
/**
|
|
166
|
-
* Export a private key as DER-encoded PKCS#8 PrivateKeyInfo.
|
|
167
|
-
*
|
|
168
|
-
* @see {@linkcode importPkcs8Der} for the inverse operation
|
|
169
|
-
* @see {@linkcode exportPkcs8Pem} for PEM output
|
|
170
|
-
* @see {@linkcode exportEncryptedPkcs8Der} for password-protected export
|
|
171
|
-
*/
|
|
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
|
+
*/
|
|
172
229
|
declare function exportPkcs8Der(privateKey: CryptoKey): Promise<Uint8Array>;
|
|
173
230
|
/**
|
|
174
|
-
* Export a public key as a JSON Web Key.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* ```ts
|
|
178
|
-
* const keys = await generateKeyPair({ kind: 'ecdsa', curve: 'P-256' });
|
|
179
|
-
* const jwk = await exportPublicJwk(keys.publicKey);
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
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
|
+
*/
|
|
182
239
|
declare function exportPublicJwk(publicKey: CryptoKey): Promise<JsonWebKey>;
|
|
183
240
|
/**
|
|
184
|
-
* Export a private key as a JSON Web Key.
|
|
185
|
-
*
|
|
186
|
-
* @see {@linkcode importPrivateJwk} for the inverse operation
|
|
187
|
-
* @see {@linkcode exportPublicJwk} for public key export
|
|
188
|
-
*/
|
|
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
|
+
*/
|
|
189
246
|
declare function exportPrivateJwk(privateKey: CryptoKey): Promise<JsonWebKey>;
|
|
190
247
|
/**
|
|
191
|
-
* Export a private key as PEM-encoded PKCS#8 PrivateKeyInfo.
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* ```ts
|
|
195
|
-
* const keys = await generateKeyPair();
|
|
196
|
-
* const pem = await exportPkcs8Pem(keys.privateKey);
|
|
197
|
-
* // -----BEGIN PRIVATE KEY-----
|
|
198
|
-
* // MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEH...
|
|
199
|
-
* // -----END PRIVATE KEY-----
|
|
200
|
-
* ```
|
|
201
|
-
*
|
|
202
|
-
* @see {@linkcode importPkcs8Pem} for the inverse operation
|
|
203
|
-
* @see {@linkcode exportEncryptedPkcs8Pem} for password-protected export
|
|
204
|
-
*/
|
|
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
|
+
*/
|
|
205
262
|
declare function exportPkcs8Pem(privateKey: CryptoKey): Promise<string>;
|
|
206
263
|
/**
|
|
207
|
-
* Export a private key as DER-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
208
|
-
*
|
|
209
|
-
* Uses PBES2 (PKCS#5 v2.1) with AES-CBC and PBKDF2. Compatible with OpenSSL.
|
|
210
|
-
*
|
|
211
|
-
* @param privateKey - The private key to export
|
|
212
|
-
* @param options - Encryption options including password and optional algorithm settings
|
|
213
|
-
*
|
|
214
|
-
* @see {@linkcode importEncryptedPkcs8Der} for the inverse operation
|
|
215
|
-
* @see {@linkcode exportEncryptedPkcs8Pem} for PEM output
|
|
216
|
-
*/
|
|
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
|
+
*/
|
|
217
274
|
declare function exportEncryptedPkcs8Der(privateKey: CryptoKey, options: EncryptedPkcs8Options): Promise<Uint8Array>;
|
|
218
275
|
/**
|
|
219
|
-
* Export a private key as PEM-encoded PBES2-encrypted PKCS#8 EncryptedPrivateKeyInfo.
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* ```ts
|
|
223
|
-
* const keys = await generateKeyPair();
|
|
224
|
-
* const pem = await exportEncryptedPkcs8Pem(keys.privateKey, { password: 'secret' });
|
|
225
|
-
* // -----BEGIN ENCRYPTED PRIVATE KEY-----
|
|
226
|
-
* // MIHsMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAc...
|
|
227
|
-
* // -----END ENCRYPTED PRIVATE KEY-----
|
|
228
|
-
* ```
|
|
229
|
-
*
|
|
230
|
-
* @see {@linkcode importEncryptedPkcs8Pem} for the inverse operation
|
|
231
|
-
*/
|
|
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
|
+
*/
|
|
232
289
|
declare function exportEncryptedPkcs8Pem(privateKey: CryptoKey, options: EncryptedPkcs8Options): Promise<string>;
|
|
233
290
|
/**
|
|
234
|
-
* Export an RSA private key as DER-encoded PKCS#1 RSAPrivateKey.
|
|
235
|
-
*
|
|
236
|
-
* PKCS#1 is the legacy RSA-only format. For algorithm-agnostic export, use
|
|
237
|
-
* {@linkcode exportPkcs8Der}.
|
|
238
|
-
*
|
|
239
|
-
* @throws {Error} If the key is not an RSA key
|
|
240
|
-
*
|
|
241
|
-
* @see {@linkcode importPkcs1Der} for the inverse operation
|
|
242
|
-
* @see {@linkcode exportPkcs1Pem} for PEM output
|
|
243
|
-
*/
|
|
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
|
+
*/
|
|
244
301
|
declare function exportPkcs1Der(privateKey: CryptoKey): Promise<Uint8Array>;
|
|
245
302
|
/**
|
|
246
|
-
* Export an RSA private key as PEM-encoded PKCS#1 RSAPrivateKey.
|
|
247
|
-
*
|
|
248
|
-
* @throws {Error} If the key is not an RSA key
|
|
249
|
-
*
|
|
250
|
-
* @see {@linkcode importPkcs1Pem} for the inverse operation
|
|
251
|
-
* @see {@linkcode exportEncryptedPkcs1Pem} for password-protected export
|
|
252
|
-
*/
|
|
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
|
+
*/
|
|
253
310
|
declare function exportPkcs1Pem(privateKey: CryptoKey): Promise<string>;
|
|
254
311
|
/**
|
|
255
|
-
* Export an RSA private key as legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
256
|
-
*
|
|
257
|
-
* Uses OpenSSL's traditional PEM encryption with MD5-based key derivation.
|
|
258
|
-
* For modern encryption, prefer {@linkcode exportEncryptedPkcs8Pem}.
|
|
259
|
-
*
|
|
260
|
-
* @throws {Error} If the key is not an RSA key
|
|
261
|
-
*
|
|
262
|
-
* @see {@linkcode importEncryptedPkcs1Pem} for the inverse operation
|
|
263
|
-
*/
|
|
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
|
+
*/
|
|
264
321
|
declare function exportEncryptedPkcs1Pem(privateKey: CryptoKey, options: LegacyPemEncryptionOptions): Promise<string>;
|
|
265
322
|
/**
|
|
266
|
-
* Export an EC private key as DER-encoded SEC 1 ECPrivateKey.
|
|
267
|
-
*
|
|
268
|
-
* SEC 1 is the legacy EC-only format. For algorithm-agnostic export, use
|
|
269
|
-
* {@linkcode exportPkcs8Der}.
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
|
|
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
|
+
*/
|
|
276
337
|
declare function exportSec1Der(privateKey: CryptoKey): Promise<Uint8Array>;
|
|
277
338
|
/**
|
|
278
|
-
* Export an EC private key as PEM-encoded SEC 1 ECPrivateKey.
|
|
279
|
-
*
|
|
280
|
-
* @throws {Error} If the key is not an EC key
|
|
281
|
-
*
|
|
282
|
-
* @see {@linkcode importSec1Pem} for the inverse operation
|
|
283
|
-
* @see {@linkcode exportEncryptedSec1Pem} for password-protected export
|
|
284
|
-
*/
|
|
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
|
+
*/
|
|
285
346
|
declare function exportSec1Pem(privateKey: CryptoKey): Promise<string>;
|
|
286
347
|
/**
|
|
287
|
-
* Export an EC private key as legacy `Proc-Type: 4,ENCRYPTED` PEM (SEC 1).
|
|
288
|
-
*
|
|
289
|
-
* Uses OpenSSL's traditional PEM encryption with MD5-based key derivation.
|
|
290
|
-
* For modern encryption, prefer {@linkcode exportEncryptedPkcs8Pem}.
|
|
291
|
-
*
|
|
292
|
-
* @throws {Error} If the key is not an EC key
|
|
293
|
-
*
|
|
294
|
-
* @see {@linkcode importEncryptedSec1Pem} for the inverse operation
|
|
295
|
-
*/
|
|
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
|
+
*/
|
|
296
357
|
declare function exportEncryptedSec1Pem(privateKey: CryptoKey, options: LegacyPemEncryptionOptions): Promise<string>;
|
|
297
358
|
/**
|
|
298
|
-
* Export a public key as PEM-encoded SubjectPublicKeyInfo.
|
|
299
|
-
*
|
|
300
|
-
* @example
|
|
301
|
-
* ```ts
|
|
302
|
-
* const keys = await generateKeyPair();
|
|
303
|
-
* const pem = await exportSpkiPem(keys.publicKey);
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
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
|
+
*/
|
|
306
367
|
declare function exportSpkiPem(publicKey: CryptoKey): Promise<string>;
|
|
307
368
|
/**
|
|
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`
|
|
312
|
-
* public handle. This bridges that gap: it
|
|
313
|
-
* strips the private components, and re-imports
|
|
314
|
-
* usage, so callers can go
|
|
315
|
-
* {@linkcode exportSpkiPem} (e.g. to
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
* @
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
* const
|
|
331
|
-
* const
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
|
|
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
|
+
*/
|
|
336
398
|
declare function derivePublicKey(privateKey: CryptoKey): Promise<CryptoKey>;
|
|
337
399
|
/**
|
|
338
|
-
* Export a key as raw base64 (no PEM headers).
|
|
339
|
-
*
|
|
340
|
-
* Returns SPKI-encoded base64 for public keys, PKCS#8-encoded base64 for private keys.
|
|
341
|
-
* Useful for compact storage or transmission where PEM overhead is undesirable.
|
|
342
|
-
*
|
|
343
|
-
* @throws {Error} If the key is a symmetric/secret key
|
|
344
|
-
*
|
|
345
|
-
* @see {@linkcode importSpkiBase64} for public key import
|
|
346
|
-
* @see {@linkcode importPkcs8Base64} for private key import
|
|
347
|
-
*/
|
|
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
|
+
*/
|
|
348
410
|
declare function exportBinaryBase64(key: CryptoKey): Promise<string>;
|
|
349
411
|
/**
|
|
350
|
-
* Import a public key from DER-encoded SubjectPublicKeyInfo.
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
366
428
|
declare function importSpkiDerOrThrow(der: Uint8Array, algorithm?: PublicKeyImportInput): Promise<CryptoKey>;
|
|
367
429
|
/**
|
|
368
|
-
* Import a public key from DER-encoded SubjectPublicKeyInfo.
|
|
369
|
-
*
|
|
370
|
-
* @see `importSpkiDerOrThrow` for the throwing variant
|
|
371
|
-
*/
|
|
430
|
+
* Import a public key from DER-encoded SubjectPublicKeyInfo.
|
|
431
|
+
*
|
|
432
|
+
* @see `importSpkiDerOrThrow` for the throwing variant
|
|
433
|
+
*/
|
|
372
434
|
declare function importSpkiDer(der: Uint8Array, algorithm?: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
373
435
|
/**
|
|
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
|
|
382
|
-
* ```
|
|
383
|
-
*
|
|
384
|
-
* @see {@linkcode exportSpkiPem} for the inverse operation
|
|
385
|
-
*/
|
|
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
|
+
*/
|
|
386
448
|
declare function importSpkiPemOrThrow(pem: string, algorithm?: PublicKeyImportInput): Promise<CryptoKey>;
|
|
387
449
|
/**
|
|
388
|
-
* Import a public key from PEM-encoded SubjectPublicKeyInfo.
|
|
389
|
-
*
|
|
390
|
-
* @see `importSpkiPemOrThrow` for the throwing variant
|
|
391
|
-
*/
|
|
450
|
+
* Import a public key from PEM-encoded SubjectPublicKeyInfo.
|
|
451
|
+
*
|
|
452
|
+
* @see `importSpkiPemOrThrow` for the throwing variant
|
|
453
|
+
*/
|
|
392
454
|
declare function importSpkiPem(pem: string, algorithm?: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
393
455
|
/**
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
399
461
|
declare function importSpkiBase64OrThrow(base64: string, algorithm?: PublicKeyImportInput): Promise<CryptoKey>;
|
|
400
462
|
/**
|
|
401
|
-
* Import a public key from base64-encoded SubjectPublicKeyInfo (no PEM headers).
|
|
402
|
-
*
|
|
403
|
-
* @see `importSpkiBase64OrThrow` for the throwing variant
|
|
404
|
-
*/
|
|
463
|
+
* Import a public key from base64-encoded SubjectPublicKeyInfo (no PEM headers).
|
|
464
|
+
*
|
|
465
|
+
* @see `importSpkiBase64OrThrow` for the throwing variant
|
|
466
|
+
*/
|
|
405
467
|
declare function importSpkiBase64(base64: string, algorithm?: PublicKeyImportInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
406
468
|
/**
|
|
407
|
-
* Import a private key from DER-encoded PKCS#8 PrivateKeyInfo.
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
* @
|
|
416
|
-
* @
|
|
417
|
-
*
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
*
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
* @
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
* @
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
* @
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
|
|
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
|
+
*/
|
|
484
562
|
declare function importPkcs1DerOrThrow(der: Uint8Array, algorithm?: ImportRsaKeyInput): Promise<CryptoKey>;
|
|
485
563
|
/**
|
|
486
|
-
* Import an RSA private key from DER-encoded PKCS#1 RSAPrivateKey.
|
|
487
|
-
*
|
|
488
|
-
* @see `importPkcs1DerOrThrow` for the throwing variant
|
|
489
|
-
*/
|
|
564
|
+
* Import an RSA private key from DER-encoded PKCS#1 RSAPrivateKey.
|
|
565
|
+
*
|
|
566
|
+
* @see `importPkcs1DerOrThrow` for the throwing variant
|
|
567
|
+
*/
|
|
490
568
|
declare function importPkcs1Der(der: Uint8Array, algorithm?: ImportRsaKeyInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
491
569
|
/**
|
|
492
|
-
* Import an RSA private key from PEM-encoded PKCS#1 RSAPrivateKey.
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
499
577
|
declare function importPkcs1PemOrThrow(pem: string, algorithm?: ImportRsaKeyInput): Promise<CryptoKey>;
|
|
500
578
|
/**
|
|
501
|
-
* Import an RSA private key from PEM-encoded PKCS#1 RSAPrivateKey.
|
|
502
|
-
*
|
|
503
|
-
* @see `importPkcs1PemOrThrow` for the throwing variant
|
|
504
|
-
*/
|
|
579
|
+
* Import an RSA private key from PEM-encoded PKCS#1 RSAPrivateKey.
|
|
580
|
+
*
|
|
581
|
+
* @see `importPkcs1PemOrThrow` for the throwing variant
|
|
582
|
+
*/
|
|
505
583
|
declare function importPkcs1Pem(pem: string, algorithm?: ImportRsaKeyInput): Promise<ImportKeyResult<CryptoKey>>;
|
|
506
584
|
/**
|
|
507
|
-
* Import an RSA private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
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
|
-
*/
|
|
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
|
+
*/
|
|
514
592
|
declare function importEncryptedPkcs1PemOrThrow(pem: string, password: string, algorithm?: ImportRsaKeyInput): Promise<CryptoKey>;
|
|
515
593
|
/**
|
|
516
|
-
* Import an RSA private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
517
|
-
*
|
|
518
|
-
* @see `importEncryptedPkcs1PemOrThrow` for the throwing variant
|
|
519
|
-
*/
|
|
594
|
+
* Import an RSA private key from legacy `Proc-Type: 4,ENCRYPTED` PEM (PKCS#1).
|
|
595
|
+
*
|
|
596
|
+
* @see `importEncryptedPkcs1PemOrThrow` for the throwing variant
|
|
597
|
+
*/
|
|
520
598
|
declare function importEncryptedPkcs1Pem(pem: string, password: string, algorithm?: ImportRsaKeyInput): Promise<ImportEncryptedKeyResult<CryptoKey>>;
|
|
521
599
|
/**
|
|
522
|
-
* Import a private key from base64-encoded PKCS#8 PrivateKeyInfo (no PEM headers).
|
|
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
|
|
528
|
-
/**
|
|
529
|
-
* Import a private key from base64-encoded PKCS#8 PrivateKeyInfo (no PEM headers).
|
|
530
|
-
*
|
|
531
|
-
* @see `importPkcs8Base64OrThrow` for the throwing variant
|
|
532
|
-
*/
|
|
533
|
-
declare function importPkcs8Base64(base64: string, algorithm
|
|
534
|
-
/**
|
|
535
|
-
* Import an EC private key from DER-encoded SEC 1 ECPrivateKey.
|
|
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
|
-
*
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
* @
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
*
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
*
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
* @see
|
|
567
|
-
*/
|
|
568
|
-
declare function
|
|
569
|
-
/**
|
|
570
|
-
* Import an EC private key from
|
|
571
|
-
*
|
|
572
|
-
*
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
* @see
|
|
582
|
-
*/
|
|
583
|
-
declare function
|
|
584
|
-
/**
|
|
585
|
-
* Import
|
|
586
|
-
*
|
|
587
|
-
* @
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
* @
|
|
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
|
-
|
|
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
|
+
*/
|
|
747
|
+
declare function encryptRsaOaepOrThrow(publicKey: CryptoKey, plaintext: Uint8Array, options?: RsaOaepOptions): Promise<Uint8Array>;
|
|
748
|
+
/**
|
|
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
|
+
*/
|
|
764
|
+
declare function encryptRsaOaep(publicKey: CryptoKey, plaintext: Uint8Array, options?: RsaOaepOptions): Promise<EncryptRsaOaepResult>;
|
|
765
|
+
/**
|
|
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
|
+
*/
|
|
787
|
+
declare function decryptRsaOaepOrThrow(privateKey: CryptoKey, ciphertext: Uint8Array, options?: RsaOaepOptions): Promise<Uint8Array>;
|
|
788
|
+
/**
|
|
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
|
+
*/
|
|
803
|
+
declare function decryptRsaOaep(privateKey: CryptoKey, ciphertext: Uint8Array, options?: RsaOaepOptions): Promise<DecryptRsaOaepResult>;
|
|
626
804
|
//#endregion
|
|
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 };
|
|
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
|