apiref
@dtinth/encrypted@0.3.1

Encrypted()  Function

Creates a CipherDecipher instance.

Signature

export function Encrypted(psk?: string): CipherDecipher

Remarks

This module is a CommonJS module. Use it from CommonJS code like this:

const encrypted = require('@dtinth/encrypted')()

To use it in a ES modules, import it like this:

import Encrypted from '@dtinth/encrypted'
const encrypted = Encrypted()

Example 1

Create a CipherDecipher instance using the key specified in the environment variable ENCRYPTION_SECRET

const encrypted = require('@dtinth/encrypted')()

Note: If the environment variable is not set, an error will be thrown.

Example 2

Create a CipherDecipher instance using a specified pre-shared key

const encrypted = require('@dtinth/encrypted')('XY0GiHz+mzZsNWP78v4fVdsoIFkfadNNh+kKuKRJUSI=')

Parameters

ParameterTypeDescription
pskstring

A pre-shared key. If not specified, the key will be loaded from the environment variable ENCRYPTION_SECRET. If that is not set, an error will be thrown. You can generate a random key from TweetNaCl.js’s website or run openssl rand -base64 32.

(Returns)CipherDecipher

An object that can be used to encrypt and decrypt data