-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
export.ts
34 lines (30 loc) · 1.05 KB
/
export.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { toSPKI as exportPublic } from '../runtime/asn1.ts'
import { toPKCS8 as exportPrivate } from '../runtime/asn1.ts'
import keyToJWK from '../runtime/key_to_jwk.ts'
import type { JWK, KeyLike } from '../types.d.ts'
/**
* Exports a runtime-specific public key representation (KeyObject or CryptoKey) to a PEM-encoded
* SPKI string format.
*
* @param key Key representation to transform to a PEM-encoded SPKI string format.
*/
export async function exportSPKI(key: KeyLike): Promise<string> {
return exportPublic(key)
}
/**
* Exports a runtime-specific private key representation (KeyObject or CryptoKey) to a PEM-encoded
* PKCS8 string format.
*
* @param key Key representation to transform to a PEM-encoded PKCS8 string format.
*/
export async function exportPKCS8(key: KeyLike): Promise<string> {
return exportPrivate(key)
}
/**
* Exports a runtime-specific key representation (KeyLike) to a JWK.
*
* @param key Key representation to export as JWK.
*/
export async function exportJWK(key: KeyLike | Uint8Array): Promise<JWK> {
return keyToJWK(key)
}