Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function doDecrypt (privateKey, cipherText) {
const plainText = decrypt(
privateKey.toString('hex'),
Buffer.from(cipherText, 'base64')
).toString()
try {
return JSON.parse(plainText)
} catch (e) {
console.warn(e)
return plainText
}
}
function doEncrypt (msg, bufKey) {
if (msg == null) return msg
if (typeof msg !== 'string') {
try {
msg = JSON.stringify(msg)
} catch (e) {
console.warn(e)
msg = String(msg)
}
}
return ecencrypt(bufKey.toString('hex'), Buffer.from(msg)).toString('base64')
}