This is a simple encryption/Decryption Controller I want condition when encryption-decryption failed then run else block otherwise go with if Block work completely fine but when encryption-decryption failed else block not works console logging an error
app.post("/playground3", async (req, res, next) => {
try {
const data = Data.findById(dataId).then((result) => {
let key = result.enc_key;
console.log(key);
let iv = result.iv;
console.log(iv);
let encryptedText = Buffer.from(req.body.data, "base64");
console.log(encryptedText);
let decipher = crypto.createDecipheriv(
"aes-256-cbc",
Buffer.from(key),
iv
);
if (!decipher) {
// MY CODE...
return res
.status(200)
.send({ success: true, encryptData, message: "Data pass IF BLOCK" });
} else {
// MY CODE
res.status(404).send({ success: false, message: "Data Not Found" });
}
});
} catch (error) {
console.log(error);
}
});