js-crypto-key-utils
Version:
Universal Module for Cryptographic Key Utilities in JavaScript, including PEM-JWK converters
58 lines (57 loc) • 2.63 kB
TypeScript
/**
* util.js
*/
import { AsnFormat, CurveTypes, DER, OctetEC, PEM, PublicOrPrivate } from './typedef';
/**
* Check if the given key is encrypted.
* @param {DER|PEM} key - Private key object in ASN.1 encoding.
* @param {AsnFormat} [format='pem'] - pem or der
* @return {boolean} - True if encrypted.
*/
export declare const isAsn1Encrypted: (key: DER | PEM, format?: AsnFormat) => boolean;
/**
* Check if the given key is public.
* @param {DER|PEM} key - Public key object in ASN.1 encoding.
* @param {AsnFormat} format - pem or der
* @return {boolean} - True if public.
*/
export declare const isAsn1Public: (key: DER | PEM, format?: AsnFormat) => boolean;
/**
* Retrieve the key type of public or private in ASN.1 format
* @param {DER|PEM} key - Key object in ASN.1 encoding.
* @param {AsnFormat} format - pem or der
* @return {'public'|'private'|'encryptedPrivate'} - The key type of the given key.
* @throws {Error} - Throws if NotSpkiNorPkcs8Key.
*/
export declare const getAsn1KeyType: (key: DER | PEM, format?: AsnFormat) => "public" | "private" | "encryptedPrivate";
/**
* Retrieve the type of SEC1 octet key.
* @param {OctetEC} sec1key - Key object in OctetEC encoding of Uint8Array.
* @param {CurveTypes} namedCurve - Name of elliptic curve like 'P-256'.
* @return {PublicOrPrivate} - public or private
* @throws {Error} - Throws if UnsupportedKeyStructure.
*/
export declare const getSec1KeyType: (sec1key: OctetEC, namedCurve: CurveTypes) => PublicOrPrivate;
/**
* Check key type of JWK.
* @param {JsonWebKey} jwkey - Key object in JWK format.
* @return {PublicOrPrivate} - public or private
* @throws {Error} - Throws if InvalidECKey, InvalidRSAKey or UnsupportedJWKType.
*/
export declare const getJwkType: (jwkey: JsonWebKey) => PublicOrPrivate;
/**
* Prune leading zeros of an octet sequence in Uint8Array for jwk formatting of RSA.
* https://tools.ietf.org/html/rfc7518#section-6.3
* @param {Uint8Array} array - The octet sequence.
* @return {Uint8Array} - An octet sequence pruned leading zeros of length equal to or shorter than the input array.
* @throws {Error} - Throws if NonUint8Array.
*/
export declare const pruneLeadingZeros: (array: Uint8Array) => Uint8Array;
/**
* Append leading zeros and generate an octet sequence of fixed length.
* @param {Uint8Array} array - An octet sequence.
* @param {Number} len - Intended length of output sequence.
* @returns {Uint8Array} - An octet sequence with leading zeros.
* @throws {Error} - Throws if NonUint8Array or InvalidLength.
*/
export declare const appendLeadingZeros: (array: Uint8Array, len: number) => Uint8Array;