sodium-javascript/README.md

47 lines
1.1 KiB
Markdown
Raw Normal View History

2020-06-24 12:49:05 +00:00
# `sodium-javascript`
2017-01-24 10:41:06 +00:00
2020-06-24 12:49:05 +00:00
[![Build Status](https://travis-ci.org/sodium-friends/sodium-javascript.svg?branch=master)](https://travis-ci.org/sodium-friends/sodium-javascript)
2017-01-24 10:41:06 +00:00
2020-06-24 12:49:05 +00:00
> WIP - a pure javascript version of [sodium-native](https://github.com/mafintosh/sodium-native).
Based on tweetnacl
2017-01-24 10:41:06 +00:00
## Usage
``` js
2020-06-24 12:49:05 +00:00
const sodium = require('sodium-javascript')
2017-01-24 10:41:06 +00:00
2020-06-24 12:49:05 +00:00
const key = Buffer.alloc(sodium.crypto_secretbox_KEYBYTES)
const nonce = Buffer.alloc(sodium.crypto_secretbox_NONCEBYTES)
2017-01-24 10:41:06 +00:00
sodium.randombytes_buf(key)
sodium.randombytes_buf(nonce)
2020-06-24 12:49:05 +00:00
const message = Buffer.from('Hello, World!')
const cipher = Buffer.alloc(message.length + sodium.crypto_secretbox_MACBYTES)
2017-01-24 10:41:06 +00:00
sodium.crypto_secretbox_easy(cipher, message, nonce, key)
console.log('Encrypted:', cipher)
2020-06-24 12:49:05 +00:00
const plainText = Buffer.alloc(cipher.length - sodium.crypto_secretbox_MACBYTES)
2017-01-24 10:41:06 +00:00
sodium.crypto_secretbox_open_easy(plainText, cipher, nonce, key)
console.log('Plaintext:', plainText.toString())
```
## API
See [sodium-native](https://github.com/mafintosh/sodium-native).
This is a work in progress so all functions are not implemented yet.
2020-06-24 12:49:05 +00:00
## Install
```
npm install sodium-javascript
```
2017-01-24 10:41:06 +00:00
## License
2020-06-24 12:49:05 +00:00
[MIT](LICENSE)