Simplifies encryption/decryption using the AES 256 GCM algorithm.
npm install bobeci-aes-256A static class that simplifies encryption/decryption using the AES 256 GCM algorithm.
Just use a one-liner to encrypt or decrypt - the IV and tag are handled
automatically.
``js
const Aes = require('aes-256-gcm');
// Must be 32 bytes.
const SHARED_SECRET = '12345678901234567890123456789012';
// Encrypt:
let { ciphertext, iv, tag } = Aes.encrypt('hi', SHARED_SECRET);
// ciphertext: 'VOE='
// iv: '0K6oPWsBAHLXYtLu5VAvsQ=='
// tag: 'hCae3Lt5sAK3oNAnUh5emA=='
// Decrypt:
let cleartext = Aes.decrypt(ciphertext, iv, tag, SHARED_SECRET;
// cleartext contains:
// 'hi'
`
Encrypts the text using the 256-bit shared key (secret) and returns an object
containing three base64-encoded strings:
`json`
{
"ciphertext": "(string)",
"iv": "(string)",
"tag": "(string)"
}
All of those strings must be passed to the end user to successfully decrypt the
text.
Decrypts the ciphertext using the iv and authentication tag tag receivedsecret`).
from the encryption function, and using the 256-bit shared key (
Returns the decoded string.