Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function unbox (ctxt, key) {
var b = Buffer.from(ctxt, 'base64')
var ptxt = chloride.crypto_secretbox_open_easy(b, key.slice(0, 24), key)
if(!ptxt) return
try {
return JSON.parse(ptxt)
} catch(err) {
console.error(err)
}
}
function unbox_detached (mac, boxed, nonce, key) {
return sodium.crypto_secretbox_open_easy(concat([mac, boxed]), nonce, key)
}
exports.secretUnbox = function secretUnbox (ctxt, key) {
var ptxt = sodium.crypto_secretbox_open_easy(ctxt, key.slice(0, 24), key)
if(!ptxt) return
return JSON.parse(ptxt.toString())
}