const decryptComment = async (comment) => {
console.log(comment);
const data = decrypt(comment).then(function (result) {
const buf2 = Buffer.from(result, 'base64').toString('ascii');
return buf2;
});
return data;
};
This is the code Im using to call decrypt function on my comment variable which is a buffer value when I print it <Buffer 01 02 02 00 78 7a ef bf bd 33 7e ef bf bd 25 5e ef bf bd 54 2d ef bf bd 7b ef bf bd ef bf bd ef bf bd 32 60 33 67 ef bf bd 5f ef bf bd 57 4b ef bf bd ... > but when I pass it to the decrypt function to decrypt to plain text. I getting an error 'InvalidCiphertextException: null
const AWS = require('aws-sdk');
AWS.config.update({
region: process.env.AWS_REGION,
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
});
const kms = new AWS.KMS();
const encrypt = async content => kms.encrypt({
KeyId: process.env.DATA_KEY_ARN,
Plaintext: content,
}).promise()
.then(data => data.CiphertextBlob)
.catch(err => console.log(err, err.stack));
const decrypt = async encryptedData => kms.decrypt({ CiphertextBlob: encryptedData })
.promise()
.then(data => data.Plaintext)
.catch(err => console.log(err, err.stack));
module.exports = {
encrypt,
decrypt,
};