first commit
This commit is contained in:
commit
e54c674afc
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Mathias Buus
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
42
README.md
Normal file
42
README.md
Normal file
@ -0,0 +1,42 @@
|
||||
# sodium-javascript
|
||||
|
||||
WIP - a pure javascript version of [sodium-native](https://github.com/mafintosh/sodium-native).
|
||||
Based on tweetnacl
|
||||
|
||||
```
|
||||
npm install sodium-javascript
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
var sodium = require('sodium-javascript')
|
||||
|
||||
var key = new Buffer(sodium.crypto_secretbox_KEYBYTES)
|
||||
var nonce = new Buffer(sodium.crypto_secretbox_NONCEBYTES)
|
||||
|
||||
sodium.randombytes_buf(key)
|
||||
sodium.randombytes_buf(nonce)
|
||||
|
||||
var message = new Buffer('Hello, World!')
|
||||
var cipher = new Buffer(message.length + sodium.crypto_secretbox_MACBYTES)
|
||||
|
||||
sodium.crypto_secretbox_easy(cipher, message, nonce, key)
|
||||
|
||||
console.log('Encrypted:', cipher)
|
||||
|
||||
var plainText = new Buffer(cipher.length - sodium.crypto_secretbox_MACBYTES)
|
||||
|
||||
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.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
20
example.js
Normal file
20
example.js
Normal file
@ -0,0 +1,20 @@
|
||||
var sodium = require('./')
|
||||
|
||||
var key = new Buffer(sodium.crypto_secretbox_KEYBYTES)
|
||||
var nonce = new Buffer(sodium.crypto_secretbox_NONCEBYTES)
|
||||
|
||||
sodium.randombytes_buf(key)
|
||||
sodium.randombytes_buf(nonce)
|
||||
|
||||
var message = new Buffer('Hello, World!')
|
||||
var cipher = new Buffer(message.length + sodium.crypto_secretbox_MACBYTES)
|
||||
|
||||
sodium.crypto_secretbox_easy(cipher, message, nonce, key)
|
||||
|
||||
console.log('Encrypted:', cipher)
|
||||
|
||||
var plainText = new Buffer(cipher.length - sodium.crypto_secretbox_MACBYTES)
|
||||
|
||||
sodium.crypto_secretbox_open_easy(plainText, cipher, nonce, key)
|
||||
|
||||
console.log('Plaintext:', plainText.toString())
|
18
package.json
Normal file
18
package.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "sodium-javascript",
|
||||
"version": "0.0.0",
|
||||
"description": "WIP - a pure javascript version of sodium-native",
|
||||
"main": "index.js",
|
||||
"dependencies": {},
|
||||
"devDependencies": {},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mafintosh/sodium-javascript.git"
|
||||
},
|
||||
"author": "Mathias Buus (@mafintosh)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/sodium-javascript/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mafintosh/sodium-javascript"
|
||||
}
|
Loading…
Reference in New Issue
Block a user