crypto
    Preparing search index...

    Class Encryption

    A utility class for aes-256-gcm encryption and decryption operations. It uses streams for processing to handle potentially large data efficiently.

    Index

    Constructors

    Methods

    • Decrypts an encrypted string created by the 'encrypt' method.

      Parameters

      • encryptedData: string

        The combined encrypted string: "[version]:[iv]:[ciphertext]".

      • key: string | Buffer<ArrayBufferLike>

        The decryption key (32 bytes).

      Returns Promise<string>

      A promise that resolves to the original plaintext string.

    • Encrypts data using AES-256-CBC with a promise-based stream approach.

      Parameters

      • data: string | Buffer<ArrayBufferLike>

        The plaintext data to encrypt (can be a Buffer or string).

      • key: string | Buffer<ArrayBufferLike>

        The encryption key (32 bytes).

      • version: string | number

        A header/version to prefix the ciphertext (e.g., version info).

      Returns Promise<string>

      A promise that resolves to the combined encrypted string: "[version]:[iv]:[ciphertext]".

    • Generates a cryptographically secure random key of the required length (32 bytes).

      Returns Buffer

      A Buffer containing the secret key.