~ev/dexbox

e1e8008662496f32b6be3b25ab9d22e04ffe8aa4 — Ev Bogue 3 years ago 58f63ad
save encrypted files to boxes folder and simply usage
3 files changed, 30 insertions(+), 21 deletions(-)

M README.md
M dexbox.js
M dexunbox.js
M README.md => README.md +11 -13
@@ 13,22 13,22 @@ How you distribute those messages is up to you; use your imagination.

### usage

To use this you'll need Node.js and you'll need to type `npm install`.
To use dexbox you'll need Node.js and you'll need to type `npm install`.

To encrypt a message you'll need to write a message and save it as a file. Then type
To encrypt a message you need to write your message into the command line:

```
node dexbox <publickey> filename 
node dexbox <publickey> 'Hello World!'
```

If you don't already have a keypair, `dexbox` will generate you an `ed25519curve` keypair and save it to disk as `keypair`.

example:
```
node dexbox 'aW83Fju6D89MZJdZrOb39++9br5S+TYKPXjg2SSEhXE=' file.txt
node dexbox 'aW83Fju6D89MZJdZrOb39++9br5S+TYKPXjg2SSEhXE=' 'Hello World!'
```

If you've done everything right, dexbox will encrypt the message to the recp you've specified and then save the file as 'outmsg'. It'll also console.log the boxed message.
If you've done everything right, dexbox will encrypt the message to the recp you've specified and then save the file as a hex encoded hash in a folder called boxes. It'll also console.log the boxed message.

### protocol



@@ 38,17 38,15 @@ The dexbox protocol is three base64 objects:
<publickey>~<nonce>~<boxedmessage>
```

To decrypt a message use the command 
To attempt to decrypt files in the `boxes` folder, run:

```
dexunbox file
node dexunbox
```

or 
You can also specify a specific file or folder with:

```
dexunbox folder
node dexunbox foldername
node dexunbox filename
```

Then dexunbox will attempt to unbox the message or all of the files in a folder using your keypair and it will console the log the messages.



M dexbox.js => dexbox.js +11 -5
@@ 2,13 2,19 @@ var fs = require('fs')
var nacl = require('tweetnacl')
    nacl.util = require('tweetnacl-util')

var boxes = __dirname + '/boxes/'

if(!fs.existsSync(boxes)) {
  fs.mkdirSync(boxes)
}

var dex = require('./crypto.js')

var keys = dex.keys()

var recp = nacl.util.decodeBase64(process.argv[2])

var message = nacl.util.decodeUTF8(fs.readFileSync(__dirname + '/' + process.argv[3], 'UTF-8'))
var message = nacl.util.decodeUTF8(process.argv[3])

var nonce = nacl.randomBytes(nacl.box.nonceLength)



@@ 16,13 22,13 @@ var boxed = nacl.box(message, nonce, recp, keys.secretKey)

var messagetosave = nacl.util.encodeBase64(keys.publicKey) + '~' + nacl.util.encodeBase64(nonce) + '~' + nacl.util.encodeBase64(boxed)

var hash = Buffer.from(nacl.hash(nacl.util.decodeUTF8(messagetosave))).toString('hex')

console.log(messagetosave)

fs.writeFile(__dirname + '/outmsg', messagetosave, 'UTF-8', function (err, success) {
fs.writeFile(boxes + hash, messagetosave, 'UTF-8', function (err, success) {
  if (err) { throw err }
  if (success) {
    console.log('saved your message to a file called outmsg')
  }
  console.log('saved your message to ' + 'boxes/' + hash)
})



M dexunbox.js => dexunbox.js +8 -3
@@ 6,7 6,11 @@ var dex = require('./crypto.js')

var keys = dex.keys()

var path = process.argv[2]
if (!process.argv[2]) {
  var path = __dirname + '/boxes/'
} else {
  var path = process.argv[2]
}

function unbox (message) {
  var sep = message.split('~')


@@ 18,8 22,8 @@ function unbox (message) {
      keys.secretKey
    )
    if (unboxed) {
      console.log('Message from: ' + sep[0])
      console.log(nacl.util.encodeUTF8(unboxed))
      //console.log('Message from: ' + sep[0])o
      console.log(nacl.util.encodeUTF8(unboxed), ' − ' + sep[0])
    }
  }
}


@@ 33,6 37,7 @@ fs.lstat(path, function (err, stats) {
    fs.readdir(path, (err, files) => {
      files.forEach(file => {
        var message = fs.readFileSync(path + '/' + file, 'UTF-8')
        console.log('Attempting to unbox ' + file)
        unbox(message)
      })
    })