Interface Cipher<EncryptInput, DecryptInput>

The Cipher interface provides methods for encrypting and decrypting data.

It defines two core functions: encrypt() for converting plaintext to ciphertext using specific algorithm parameters, and decrypt() for the reverse process, turning ciphertext back into plaintext. These methods operate asynchronously and return promises that resolve to the processed data, whether encrypted or decrypted.

The interface is designed to be flexible, accommodating various encryption algorithms and their unique parameters. It defaults to using EnclosedEncryptParams and EnclosedDecryptParams, which are intended to be used with a closure that captures the key and algorithm-specific parameters so that arbitrary data can be encrypted and decrypted without exposing the key or parameters to the caller. However, the interface can be extended to support other parameter types, such as EncryptParams and DecryptParams, which are intended to be used when the key and algorithm-specific parameters are known to the caller.

interface Cipher<EncryptInput, DecryptInput> {
    decrypt(params): Promise<Uint8Array>;
    encrypt(params): Promise<Uint8Array>;
}

Type Parameters

Implemented by

Methods

  • Decrypts the provided data.

    Parameters

    • params: DecryptInput

      The parameters for the decryption operation.

    Returns Promise<Uint8Array>

    A Promise which will be fulfilled with the decrypted data.

    Remarks

    The decrypt() method of the Cipher interface decrypts encrypted data.

    It typically takes the data to decrypt (also known as "ciphertext") and algorithm-specific parameters as input and returns the decrypted data (also known as "plaintext").

  • Encrypts the provided data.

    Parameters

    • params: EncryptInput

      The parameters for the encryption operation.

    Returns Promise<Uint8Array>

    A Promise which will be fulfilled with the encrypted data.

    Remarks

    The encrypt() method of the Cipher interface encrypts data.

    It typically takes the data to encrypt (also known as "plaintext") and algorithm-specific parameters as input and returns the encrypted data (also known as "ciphertext").