Encrypts and decrypts a string using native browser apis.
This is geared towards easy use and thereby the configuration is quite limited with only 'AES-GCM'
and 'AES-CBC' being implemented.
There is a random 'AES-GCM' key generator and one that derives a key from a password and salt.
import { encryptAES, generateKeyFromPasswordAndSalt } from '@witzbould/utils-encryption';
const secret = 'my secret';
const key = await generateKeyFromPasswordAndSalt('password', 'salt');
const encrypted = await encryptAES(key, secret);
console.log(encrypted);
import { decryptAES, generateKeyFromPasswordAndSalt } from '@witzbould/utils-encryption';
const key = await generateKeyFromPasswordAndSalt('password', 'salt');
const decrypted = await decryptAES(key, encrypted);
console.log(decrypted); // my secret
There is also a version with node apis.
import { encrypt, decrypt } from '@witzbould/utils-encryption/node';
const plaintext = 'Hello, world!';
const encryptedText = encrypt(plaintext);
console.log('Encrypted Text:', encryptedText);
const decryptedText = decrypt(encryptedText);
console.log('Decrypted Text:', decryptedText);