Authenticated data encryption with AES-GCM. Allows to encrypt arbitrary data in a cryptographically secure & modern way.
A simple wrapper over node.js and browser aes-gcm implementations. No dependencies.
npm install micro-aes-gcm
;const key = Uint8Array;const plaintext = "Hello world";const ciphertext = await aes;const plaintext = await aes;console;// Also works in browsers
encrypt can be either a Uint8Array, or a string. If it's a string,
new TextDecoder().encode(plaintext) would be executed before passing it further.
decrypt always returns
Uint8Array. If you've encrypted UTF-8 string,
toUTF8(result) should be enough to get it back.
Secretbox receives one key, and one plaintext.
The output format is:
iv + ciphertext + mac:
ivis 12 bytes; it's an initialization vector for AES-GCM mode.
ciphertextlength depends on plaintext
macis 16 bytes; AES-GCM calculates this authentication tag for us.
To slice through IV and MAC, you can use
const ciphertext = await ;const iv = ciphertext;const mac = ciphertext;
DJB's secretbox uses XSalsa20-Poly1305. We'll use AES-GCM, which is also a good choice. DJB mentioned the AES box in his TODOs.
AES has been selected over Salsa, because it's natively implemented in Node & browsers and doesn't require any 3rd-party libraries.
MIT (c) Paul Miller (https://paulmillr.com), see LICENSE file.