UNPKG

@unvision/jose

Version:

Implementation of the RFCs of the JOSE Working Group.

75 lines (74 loc) 3.25 kB
/// <reference types="node" /> import { SupportedJsonWebEncryptionContentEncryptionAlgorithm } from './types/supported-jsonwebencryption-content-encryption-algorithm'; /** * Abstract Base Class for the JSON Web Encryption Content Encryption Algorithms. * * All JSON Web Encryption Content Encryption Algorithms **MUST** extend this base class and implement its abstract methods. * * @see https://www.rfc-editor.org/rfc/rfc7518.html#section-5 */ export declare abstract class JsonWebEncryptionContentEncryptionAlgorithm { /** * Name of the JSON Web Encryption Content Encryption Algorithm. */ protected readonly algorithm: SupportedJsonWebEncryptionContentEncryptionAlgorithm; /** * Size of the Content Encryption Key in bits. */ readonly cekSize: number; /** * Size of the Initialization Vector in bits. */ readonly ivSize: number; /** * Instantiates a new JSON Web Encryption Content Encryption Algorithm to Encrypt and Decrypt a Plaintext. * * @param algorithm Name of the JSON Web Encryption Content Encryption Algorithm. * @param cekSize Size of the Content Encryption Key in bits. * @param ivSize Size of the Initialization Vector in bits. */ constructor(algorithm: SupportedJsonWebEncryptionContentEncryptionAlgorithm, cekSize: number, ivSize: number); /** * Generates a new Content Encryption Key. */ generateContentEncryptionKey(): Promise<Buffer>; /** * Generates a new Initialization Vector. */ generateInitializationVector(): Promise<Buffer>; /** * Checks if the provided Content Encryption Key can be used by the JSON Web Encryption Content Encryption Algorithm. * * @param key Content Encryption Key to be checked. * @throws {InvalidJsonWebEncryptionException} The provided Content Encryption Key is invalid. */ validateContentEncryptionKey(key: Buffer): void; /** * Checks if the provided Initialization Vector can be used by the JSON Web Encryption Content Encryption Algorithm. * * @param iv Initialization Vector to be checked. * @throws {InvalidJsonWebEncryptionException} The provided Initialization Vector is invalid. */ validateInitializationVector(iv: Buffer): void; /** * Encrypts the provided Plaintext. * * @param plaintext Plaintext to be Encrypted. * @param aad Additional Authenticated Data. * @param iv Initialization Vector. * @param key Content Encryption Key used to Encrypt the provided Plaintext. * @returns Resulting Ciphertext and Authentication Tag. */ abstract encrypt(plaintext: Buffer, aad: Buffer, iv: Buffer, key: Buffer): Promise<[Buffer, Buffer]>; /** * Decrypts the provided Ciphertext back to its original Plaintext. * * @param ciphertext Ciphertext to be Decrypted. * @param aad Additional Authenticated Data. * @param iv Initialization Vector. * @param tag Authentication Tag. * @param key Content Encryption Key used to Decrypt the provided Ciphertext. * @returns Resulting Plaintext. */ abstract decrypt(ciphertext: Buffer, aad: Buffer, iv: Buffer, tag: Buffer, key: Buffer): Promise<Buffer>; }