How to securely encrypt data in Javascript with NaCl high level library
1 min readOct 27, 2018
Hi!
In this tutorial, I will show you how you can encrypt or decrypt data in Javascript with TweetNaCl.js. It is a port of NaCl (Networking and Cryptography library) to Javascript. We’ll also see how to store the encrypted data in files.
To install TweetNaCl, do the following:
npm install tweetnacl
We also need tweetnacl-util
to encode/decode in UTF-8 and Base64:
npm install tweetnacl-util
Note that tweetnacl-util
is bad, they reversed names of functions to encode and decode UTF8…
Unfortunately, this port of NaCl don’t provide a key derivation function, so we’ll use scryptsy
:
npm install scryptsy
Encryption
Decryption
Thanks for reading!