@vnodes/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

    Properties

    ALGORITHM: string = 'aes-256-gcm'
    ENCODING: BufferEncoding = 'hex'
    IV_LENGTH: number = 12
    KEY_LENGTH: number = 32

    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.

    • Validates that the provided key is the correct length for the chosen algorithm.

      Parameters

      • key: string | Buffer<ArrayBufferLike>

        The encryption key (Buffer or string that can be converted to Buffer).

      Returns void