import { DER, OctetEC, PEM, KeyFormat, CurveTypes, KeyExportOptions, JwkThumbprintFormat, HashTypes } from './typedef'; /** * Key class to abstract public and private key objects in string or binary. * This class provides functions to interchangeably convert key formats, * and key objects will be used for the root package, js-crypto-utils, as inputs to exposed APIs. */ export declare class Key { private _type; private _jwk; private _der; private _oct; private _isEncrypted; private _current; /** * @constructor * @param {KeyFormat} format - Key format: 'jwk', 'der', 'pem' or 'oct' (only for ECC key). * @param {JsonWebKey|PEM|DER|OctetEC} key - Key object in the specified format. * @param {Object} [options={}] - Required if format='oct', and then it is {namedCurve: String}. * @throws {Error} - Throws if the input format and key are incompatible to the constructor. */ constructor(format: KeyFormat, key: JsonWebKey | PEM | DER | OctetEC, options?: { namedCurve?: CurveTypes; }); /** * Set a key in JWK to the Key object. * @param {JsonWebKey} jwkey - The Json Web Key. * @private */ private _setJwk; /** * Set a key in DER or PEM to the Key object. * @param {DER|PEM} asn1key - The DER key byte array or PEM key string. * @param {String} format - 'der' or 'pem' specifying the format. * @private */ private _setAsn1; /** * Set a key in SEC1 = Octet format to the Key Object. * @param {OctetEC} sec1key - The Octet SEC1 key byte array. * @param {CurveTypes} namedCurve - Name of curve like 'P-256'. * @private */ private _setSec1; /** * Set the current internal status. In particular, manage what the object is based on. * @private */ private _setCurrentStatus; /** * Convert the stored key and export the key in desired format. * Imported key must be basically decrypted except the case where the key is exported as-is. * @param {String} format - Intended format of exported key. 'jwk', 'pem', 'der' or 'oct' * @param {KeyExportOptions} [options={}] - Optional arguments. * @return {Promise} - Exported key object. */ export(format?: KeyFormat, options?: KeyExportOptions): Promise; /** * Encrypt stored key and set the encrypted key to this instance. * @param {String} passphrase - String passphrase. * @return {Promise} - Always true otherwise thrown. * @throws {Error} - Throws if AlreadyEncrypted. */ encrypt(passphrase: string): Promise; /** * Decrypted stored key and set the decrypted key in JWK to this instance. * @param {String} passphrase - String passphrase. * @return {Promise} - Always true otherwise thrown. * @throws {Error} - Throws if NotEncrypted or FailedToDecrypt. */ decrypt(passphrase: string): Promise; /** * Conpute JWK thumbprint specified in RFC7638 {@link https://tools.ietf.org/html/rfc7638}. * @param {HashTypes} [alg='SHA-256'] - Name of hash algorithm for thumbprint computation like 'SHA-256'. * @param {JwkThumbpirntFormat} [output='binary'] - Output format of JWK thumbprint. 'binary', 'hex' or 'base64'. * @return {Promise} - Computed thumbprint. * @throws {Error} - Throws if DecryptionRequired. */ getJwkThumbprint(alg?: HashTypes, output?: JwkThumbprintFormat): Promise; /** * Get keyType in JWK format * @return {Promise} - 'RSA' or 'EC' * @throws {Error} - Throws if DecryptionRequired. */ get keyType(): Promise; /** * Get jwkThumbprint of this key. * @return {Promise} - Returns binary thumbprint. */ get jwkThumbprint(): Promise; /** * Check if this is encrypted. * @return {boolean} */ get isEncrypted(): boolean; /** * Check if this is a private key. * @return {boolean} */ get isPrivate(): boolean; /** * Returns the key in DER format. * @return {Promise} */ get der(): Promise; /** * Returns the key in PEM format. * @return {Promise} */ get pem(): Promise; /** * Returns the key in JWK format * @return {Promise} */ get jwk(): Promise; /** * Returns the 'EC' key in Octet SEC1 format. * @return {Promise} */ get oct(): Promise; }