AES-256-GCM encryption for high security Automatic salt and IV generation for each encryption operation Key derivation using scrypt for added security against brute-force attacks Customizable encoding for encrypted output Easy-to-use API for encrypting and decrypting strings
npm install symmetrical-encryption
or:
yarn add symmetrical-encryption
or:
pnpm add symmetrical-encryption
or:
bun install symmetrical-encryption
Encrypting Data
To encrypt data, provide the plaintext string, your secret key, and optionally specify the output encoding (defaults to Base64).
import { encrypt } from "symmetrical-encryption" // Prefferably stored more securely; const secretKey = process.env.SECRET_KEY const secretKey = "your-very-secure-secret-key" const data = "Hi mom!" const encryptedData = encrypt(data, secretKey, { encoding: "base64" }) // option object is optional console.log("Encrypted Data:", encryptedData) // base64 encoded string
Decrypting Data
To decrypt data, provide the encrypted string and your secret key. The function automatically extracts the salt, IV, and authentication tag from the encrypted data.
import { decrypt } from "symmetrical-encryption" // Prefferably stored more securely; const secretKey = process.env.SECRET_KEY const secretKey = "your-very-secure-secret-key" const encryptedData = "..." // The output from the encrypt function const decryptedData = decrypt(encryptedData, secretKey) console.log("Decrypted Data:", decryptedData) // "Hi mom!"
Valid encoding options are:
type ValidEncodings = "hex" | "base64" | "latin1"
MIT
npx changeset
npx changeset version
Add Package
deno add jsr:@hev/symmetrical-encryption
Import symbol
import * as symmetrical_encryption from "@hev/symmetrical-encryption";
Import directly with a jsr specifier
import * as symmetrical_encryption from "jsr:@hev/symmetrical-encryption";
Add Package
pnpm i jsr:@hev/symmetrical-encryption
pnpm dlx jsr add @hev/symmetrical-encryption
Import symbol
import * as symmetrical_encryption from "@hev/symmetrical-encryption";
Add Package
yarn add jsr:@hev/symmetrical-encryption
yarn dlx jsr add @hev/symmetrical-encryption
Import symbol
import * as symmetrical_encryption from "@hev/symmetrical-encryption";
Add Package
npx jsr add @hev/symmetrical-encryption
Import symbol
import * as symmetrical_encryption from "@hev/symmetrical-encryption";
Add Package
bunx jsr add @hev/symmetrical-encryption
Import symbol
import * as symmetrical_encryption from "@hev/symmetrical-encryption";