Salsa20 is a family of 256-bit stream ciphers designed in 2005 and submitted to eSTREAM, the ECRYPT Stream Cipher Project. Salsa20 has progressed to the third round of eSTREAM without any changes. The 20-round stream cipher Salsa20/20 is consistently faster than AES and is recommended by the designer for typical cryptographic applications.
Implementation derived from
- The Salsa20 family of stream ciphers
- Salsa20 specification
- Salsa20 design
npm install js-salsa20 --save
Encrypt message with key and nonce
;const key = Uint8Array...; // 32 bytes keyconst nonce = Uint8Array...; // 8 bytes nonceconst message = Uint8Array...; // some data as bytes array// Encrypt //const encrypt = key nonce;// now encrypt contains bytes array of encrypted message
Decrypt encrypted message with key and nonce
;const key = Uint8Array...; // 32 bytes keyconst nonce = Uint8Array...; // 8 bytes nonceconst encrypt = Uint8Array...; // some data as bytes array// Encrypt //const message = key nonce;// now message contains bytes array of original message
That all. If something happens, Error will be thrown. More examples you can find in tests files.