aes-256-gcm

Simplifies encryption/decryption using the AES 256 GCM algorithm.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
aes-256-gcm
201.0.36 years ago6 years agoMinified + gzip package size for aes-256-gcm in KB

Readme

AES-256-GCM encryption/decryption shortcuts #
A 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.

Example ##

```js const Aes = require('aes-256-gcm'); // Must be 32 bytes. const SHAREDSECRET = '12345678901234567890123456789012'; // Encrypt: let { ciphertext, iv, tag } = Aes.encrypt('hi', SHAREDSECRET); // ciphertext: 'VOE=' // iv: '0K6oPWsBAHLXYtLu5VAvsQ==' // tag: 'hCae3Lt5sAK3oNAnUh5emA==' // Decrypt: let cleartext = Aes.decrypt(ciphertext, iv, tag, SHAREDSECRET; // cleartext contains: // 'hi' ```

Methods ##

static encrypt(text, secret) ###

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.

static decrypt(ciphertext, iv, tag, secret) ###

Decrypts the ciphertext using the iv and authentication tag tag received from the encryption function, and using the 256-bit shared key (secret). Returns the decoded string.