git ssb

1+

Dominic / ssb-keys



Commit 17afc23651a3a861a684676695d0562d07145584

implement encryption, decryption

Dominic Tarr committed on 7/1/2015, 10:53:00 PM
Parent: 1a34ba680e6e6efa7e5c46b8684644ecba505534

Files changed

index.jschanged
package.jsonchanged
index.jsView
@@ -7,10 +7,13 @@
77 var createHmac = require('hmac')
88 var Blake2s = require('blake2s')
99
1010 var ecc = require('./eccjs')
11+var sodium = require('sodium').api
1112 var isRef = require('ssb-ref')
1213
14+var pb = require('private-box')
15+
1316 //UTILS
1417
1518 function clone (obj) {
1619 var _obj = {}
@@ -305,6 +308,26 @@
305308 // ts: Date.now(),
306309 // public: keys.public
307310 // })
308311 //}
309-//
310312
313+exports.box = function (msg, recipients) {
314+ msg = new Buffer(JSON.stringify(msg))
315+
316+ recipients = recipients.map(function (keys) {
317+ var public = keys.public || keys
318+ return sodium.crypto_sign_ed25519_pk_to_curve25519(toBuffer(public))
319+ })
320+
321+ //it's since the nonce is 24 bytes (a multiple of 3)
322+ //it's possible to concatenate the base64 strings
323+ //and still have a valid base64 string.
324+ return pb.multibox(msg, recipients).toString('base64')+'.box'
325+}
326+
327+exports.unbox = function (boxed, keys) {
328+ boxed = toBuffer(boxed)
329+ var sk = sodium.crypto_sign_ed25519_sk_to_curve25519(toBuffer(keys.private || keys))
330+
331+ var msg = pb.multibox_open(boxed, sk)
332+ if(msg) return JSON.parse(''+msg)
333+}
package.jsonView
@@ -13,13 +13,14 @@
1313 "eccjs": "git://github.com/dominictarr/eccjs.git#586f6d47507184a2efe84684ed0a30605cbc43a5",
1414 "hmac": "~1.0.1",
1515 "libsodium-wrappers": "^0.2.8",
1616 "mkdirp": "~0.5.0",
17- "sodium": "^1.0.17",
17+ "private-box": "0.0.0",
18+ "sodium": "git://github.com/dominictarr/node-sodium.git",
1819 "ssb-ref": "~0.0.0"
1920 },
2021 "devDependencies": {
21- "tape": "~3.0.0"
22+ "tape": "^3.0.3"
2223 },
2324 "browser": {
2425 "./sodium": "./browser-sodium"
2526 },

Built with git-ssb-web