Encrypted()  Function

Creates a CipherDecipher instance.


export function Encrypted(psk?: string): CipherDecipher


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=')



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.


An object that can be used to encrypt and decrypt data