Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
decrypt(key, message)
{
try
{
message = _sodium.from_hex(message);
return _sodium.to_string(_sodium.crypto_secretbox_open_easy(message.slice(_sodium.crypto_secretbox_NONCEBYTES), message.slice(0, _sodium.crypto_secretbox_NONCEBYTES), _sodium.from_hex(key)));
}
catch(e)
{
this._adapter.log.warn(JSON.stringify(e.message));
return false;
}
}
decrypt(key, message)
{
try
{
let cypherText = new Buffer(payload, 'base64');
let nonce = cypherText.slice(0, _sodium.crypto_secretbox_NONCEBYTES);
let encryptionKey = new Buffer(32);
encryptionKey.fill(0);
encryptionKey.write(key);
return _sodium.crypto_secretbox_open_easy(cypherText.slice(_sodium.crypto_secretbox_NONCEBYTES), nonce, encryptionKey, 'text');
}
catch(e)
{
this._adapter.log.warn(e.message);
return false;
}
}
}
export const decrypt = (cipher: Data, nonce: Data, key: Key) => {
if (cipher.length < sodium.crypto_secretbox_MACBYTES) return null
let msg
try {
msg = sodium.crypto_secretbox_open_easy(cipher, nonce, key)
} catch (e) {
return null
}
return msg
}
var decrypt = function(data) {
var ct = new Uint8Array(data.length);
for (var i=0; i < data.length; i++) {
ct[i] = data.readUInt8(i);
}
var decryptedData = sodium.crypto_secretbox_open_easy(ct, encryptionNonce, encryptionKey);
return new Buffer(getValuesFromMap(decryptedData)).toString();
};
decrypt = constructedKey => {
const salt = toBuffer(constructedKey.slice(0, 8));
const encryptedSk = constructedKey.slice(8);
const encryptionKey = pbkdf2.pbkdf2Sync(passphrase, salt, 32768, 32, 'sha512');
return sodium.crypto_secretbox_open_easy(
new Uint8Array(encryptedSk),
new Uint8Array(24),
new Uint8Array(encryptionKey)
);
};
}