AES-256 Encrypt/Decrypt

Security

AES-256-GCM encryption for secure messages with PBKDF2 key derivation.

Import

Import
import { encrypt } from 'toolmetry';

API Reference

FunctionParametersReturnsDescription
aesEncryptplaintext: string, secret: stringstringEncrypt text using AES-256-GCM (Node.js sync)
aesDecryptencrypted: string, secret: stringstringDecrypt AES-256-GCM encrypted text (Node.js)
aesEncryptAsyncplaintext: string, secret: stringPromise<string>Async encrypt (browser + Node)
aesDecryptAsyncencrypted: string, secret: stringPromise<string>Async decrypt (browser + Node)

Examples

Encrypt & Decrypt (Node.js)
import { aesEncrypt, aesDecrypt } from 'toolmetry';

const encrypted = aesEncrypt('Hello, secret!', 'my-password');
// "iv:authTag:ciphertext" (Base64 parts)

const decrypted = aesDecrypt(encrypted, 'my-password');
// "Hello, secret!"
Async (Browser)
import { aesEncryptAsync, aesDecryptAsync } from 'toolmetry';

const encrypted = await aesEncryptAsync('Hello!', 'my-password');
const decrypted = await aesDecryptAsync(encrypted, 'my-password');
// "Hello!"

Try It Live