git ssb

0+

Dominic / ssb-peer-invites



Tree: e106db19b5757a1b96390c4ef9bc5603e3075aa1

Files: e106db19b5757a1b96390c4ef9bc5603e3075aa1 / util.js

679 bytesRaw
1var chloride = require('chloride')
2
3function box (data, key) {
4 if(!data) return
5 var b = new Buffer(JSON.stringify(data))
6 return chloride.crypto_secretbox_easy(b, key.slice(0, 24), key).toString('base64')
7}
8
9function unbox (ctxt, key) {
10 //var b = new Buffer(JSON.stringify(data))
11 var b = new Buffer(ctxt, 'base64')
12 var ptxt = chloride.crypto_secretbox_open_easy(b, key.slice(0, 24), key)
13 if(!ptxt) return
14 try {
15 return JSON.parse(ptxt)
16 } catch(err) {
17 console.error(err)
18 }
19}
20
21
22function hash(s) {
23 return chloride.crypto_hash_sha256(
24 'string' == typeof s ? new Buffer(s, 'utf8') : s
25 )
26}
27
28exports.hash = hash
29exports.box = box
30exports.unbox = unbox
31

Built with git-ssb-web