mirror of
https://github.com/hanzoai/jose.git
synced 2026-09-24 17:00:01 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
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)
|
|
}
|