git ssb

0+

Dominic / ssb-peer-invites



Tree: fe51981dcffa9ecd1ade80ce5ce03f11c28229ab

Files: fe51981dcffa9ecd1ade80ce5ce03f11c28229ab / util.js

634 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(ctxt, 'base64')
11 var ptxt = chloride.crypto_secretbox_open_easy(b, key.slice(0, 24), key)
12 if(!ptxt) return
13 try {
14 return JSON.parse(ptxt)
15 } catch(err) {
16 console.error(err)
17 }
18}
19
20
21function hash(s) {
22 return chloride.crypto_hash_sha256(
23 'string' == typeof s ? new Buffer(s, 'utf8') : s
24 )
25}
26
27exports.hash = hash
28exports.box = box
29exports.unbox = unbox
30

Built with git-ssb-web