@guarani/jose
Version:
Implementation of the RFCs of the JOSE Working Group.
75 lines (74 loc) • 3.32 kB
TypeScript
/// <reference types="node" />
import { AuthenticatedEncryption } from './types/authenticated-encryption';
import { SupportedJsonWebEncryptionContentEncryptionAlgorithm } from './types/supported-jsonwebencryption-contentencryption-algorithm';
/**
* Abstract Base Class for {@link https://www.rfc-editor.org/rfc/rfc7518.html#section-5 RFC 7518 Section 5}.
*
* All JSON Web Encryption Content Encryption Algorithms supported by Guarani **MUST** extend this base class
* and implement its abstract methods.
*/
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 cekSize Size of the Content Encryption Key in bits.
* @param ivSize Size of the Initialization Vector in bits.
* @param algorithm Name of the JSON Web Encryption Content Encryption Algorithm.
*/
constructor(cekSize: number, ivSize: number, algorithm: SupportedJsonWebEncryptionContentEncryptionAlgorithm);
/**
* Generates a new Initialization Vector.
*/
generateInitializationVector(): Promise<Buffer>;
/**
* Generates a new Content Encryption Key.
*/
generateContentEncryptionKey(): Promise<Buffer>;
/**
* 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.
*/
protected validateInitializationVector(iv: Buffer): void;
/**
* 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;
/**
* Encrypts the provided Plaintext.
*
* @param plaintext Plaintext to be Cncrypted.
* @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<AuthenticatedEncryption>;
/**
* 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>;
}