js-crypto-key-utils
Version:
Universal Module for Cryptographic Key Utilities in JavaScript, including PEM-JWK converters
33 lines (32 loc) • 1.67 kB
TypeScript
/**
* asn1enc.js
*/
import { AsnEncryptOptionsWithPassphrase, DER, PEM } from './typedef';
/**
* Convert jwk to spki/pkcs8 in string or binary format.
* @param {JsonWebKey} jwkey - A key object in JWK format to be encoded.
* @param {boolean} outputPublic - Derive public key from private key when true
* @param {AsnFormat} format - 'pem' or 'der'
* @param {boolean} compact - 'true' or 'false' for EC public key compressed representation in der/pem
* @param {String} passphrase - if passphrase is given and the given key is private key, it will be encoded with the passphrase.
* @param {AsnEncryptOptionsWithPassphrase} encOptions - ASN.1 encryption options
* @return {Uint8Array|String} - Encoded private key in DER or PEM
*/
export declare const fromJwk: (jwkey: JsonWebKey, format: 'pem' | 'der', { outputPublic, compact, encOptions }: {
outputPublic?: boolean | undefined;
compact?: boolean | undefined;
encOptions?: AsnEncryptOptionsWithPassphrase | undefined;
}) => Promise<PEM | DER>;
/**
* Convert SPKI/PKCS8 key in string or binary format to JWK.
* @param {PEM|DER} key - Key object.
* @param {AsnFormat} format - 'pem' or 'der'
* @param {boolean} [outputPublic] - Export public key even from private key if true.
* @param {String} [passphrase] - Encrypt private key if passphrase is given.
* @return {JsonWebKey} - Obtained key object in JWK format.
* @throws {Error} Throws if UnsupportedKeyStructure, UnsupportedKey or InvalidKeyType.
*/
export declare const toJwk: (key: PEM | DER, format: 'pem' | 'der', { outputPublic, passphrase }: {
outputPublic?: boolean | undefined;
passphrase: string;
}) => Promise<JsonWebKey>;