js-crypto-utils
Version:
JavaScript cryptographic utilities for OpenSSL-WebCrypto compatibility including PEM/X509-JWK converter.
53 lines (52 loc) • 3.13 kB
TypeScript
/**
* pkc.js
*/
import { DecryptionOption, EncryptionOption, HashTypes, KeyGenOptions, KeyPair, KeyTypes, PKCCiphertextObject, SigningOption } from './typedef';
/**
* Generate key pair in JWK format
* @param {'EC'|'RSA'} [keyType='EC'] - Type of public/private key.
* @param {ECKeyGenerationOption|RSAKeyGenerationOption} [options={}] - Key generation options.
* @return {Promise<{publicKey: JsonWebKey, privateKey: JsonWebKey}>} - Generated key pair in JWK format.
*/
export declare const generateKey: (keyType: KeyTypes | undefined, options: KeyGenOptions) => Promise<KeyPair>;
/**
* Sign message with given private key in jwk
* @param {Uint8Array} msg - Message byte array to be signed.
* @param {Key} privateKey - Private key object for signing.
* @param {String} [hash='SHA-256'] - Name of hash algorithm like 'SHA-256'.
* @param {RSASigningOption|ECSigningOption} [options={}] - Signing options.
* @return {Promise<Uint8Array>} - Signature byte array.
* @throws {Error} - Throws if NonKeyObject or UnsupportedKeyType.
*/
export declare const sign: (msg: Uint8Array, privateKey: any, hash?: HashTypes, options?: SigningOption) => Promise<Uint8Array>;
/**
* Verify message with given public key
* @param {Uint8Array} msg - A plaintext message to be verified.
* @param {Uint8Array} sig - Signature byte array.
* @param {Key} publicKey - Public key object for verification.
* @param {String} [hash='SHA-256'] - Name of hash algorithm like 'SHA-256'.
* @param {RSASigningOption|ECSigningOption} [options={}] - Signing options.
* @return {Promise<boolean>} - Result of verification.
* @throws {Error} - Throws if NonKeyObject or UnsupportedKeyType.
*/
export declare const verify: (msg: Uint8Array, sig: Uint8Array, publicKey: any, hash?: HashTypes, options?: SigningOption) => Promise<boolean>;
/**
* Encryption with public key algorithm. in case of ECDH.
* Session key is derived from HKDF and the data itself will be encrypted by symmetric cipher.
* @param {Uint8Array} msg - Plaintext message to be encrypted.
* @param {Key} publicKey - Public key object.
* @param {RSAEncryptionOption|ECEncryptionOptions} [options={}] - Encryption options.
* @return {Promise<PKCCiphertextObject>} - Encrypted message object.
* @throws {Error} - Throws if NonKeyObject, MissingOrInvalidPrivateKeyForECDH, or UnsupportedKeyType.
*/
export declare const encrypt: (msg: Uint8Array, publicKey: any, options?: EncryptionOption) => Promise<PKCCiphertextObject>;
/**
* Decryption with public key algorithm. in case of ECDH
* Session key is derived from HKDF and the data itself will be decrypted by symmetric cipher.
* @param {Uint8Array} data - Encrypted message body, i.e., PKCCiphertextObject.data.
* @param {Key} privateKey - Private key object
* @param {RSAEncryptionOption|ECDecryptionOptions} [options={}] - Decryption Options.
* @return {Promise<Uint8Array>} - Decrypted message byte array.
* @throws {Error} - Throws if NonKeyObject, MissingPublicKeyForECDH, or UnsupportedKeyType.
*/
export declare const decrypt: (data: Uint8Array, privateKey: any, options: DecryptionOption) => Promise<Uint8Array>;