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
Parameter | Type | Description |
---|---|---|
psk | string | A pre-shared key. If not specified, the key will be loaded from the environment variable |
(Returns) | CipherDecipher | An object that can be used to encrypt and decrypt data |