• A function that can be used to encrypt arbitrary data using the AES-256-CBC algorithm.

    Parameters

    • data: string | Buffer

      The Buffer instance or String containing the data to be encrypted.

    • key: Buffer

      A Buffer instance containing the key to be used by the AES-256-CBC algorithm for encrypting data. Ideally, that buffer would be of size 32 bytes, but, internally, this function will prepare the key with prepareKey in order to make it 32 bytes. This allows for passwords of arbitrary sizes, even if shorter passwords are less secure.

    Returns Buffer

    A Buffer instance containing the encrypted data, prepended by an internally randomly generated 128-bit (i.e., 16 bytes) initialization vector.

    Note

    Internally, this function uses Node's crypto.Cipher class to perform encryption.

    Remark

    Encrypting the same data twice using the same password will yield different outputs, as the initialization vector is randomly generated on each call.

    See

    encryptAsync

Generated using TypeDoc