Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function unseal(cipher, publicKey, secretKey) {
if (cipher.length < sodium.crypto_box_SEALBYTES) return null
var msg = new Buffer(cipher.length - sodium.crypto_box_SEALBYTES)
if (!sodium.crypto_box_seal_open(msg, cipher, publicKey, secretKey)) return null
return msg
}
function unseal(cipher, publicKey, secretKey) {
if (cipher.length < sodium.crypto_box_SEALBYTES) return null
var msg = Buffer.alloc(cipher.length - sodium.crypto_box_SEALBYTES)
if (!sodium.crypto_box_seal_open(msg, cipher, publicKey, secretKey)) return null
return msg
}
function unseal(cipher, publicKey, secretKey) {
if (cipher.length < sodium.crypto_box_SEALBYTES) return null
var msg = new Buffer(cipher.length - sodium.crypto_box_SEALBYTES)
if (!sodium.crypto_box_seal_open(msg, cipher, publicKey, secretKey)) return null
return msg
}
export function openSealedBox(
keyPair: EncodedEncryptionKeyPair,
sealedBox: EncodedSealedBox
): Buffer {
const keyPairBuffer = decodePair(keyPair)
const sealedBoxBuffer = decode(sealedBox)
const message = Buffer.alloc(sealedBoxBuffer.length - sodium.crypto_box_SEALBYTES)
const success = sodium.crypto_box_seal_open(
message,
sealedBoxBuffer,
keyPairBuffer.publicKey,
keyPairBuffer.secretKey
)
if (!success) throw new Error('Unable to open sealed box')
return message
}
function seal(msg, publicKey) {
var cipher = new Buffer(msg.length + sodium.crypto_box_SEALBYTES)
sodium.crypto_box_seal(cipher, msg, publicKey)
return cipher
}
function seal(msg, publicKey) {
var cipher = Buffer.alloc(msg.length + sodium.crypto_box_SEALBYTES)
sodium.crypto_box_seal(cipher, msg, publicKey)
return cipher
}