对此的任何帮助将不胜感激:)。我正在尝试创建一个 firebase 函数来使用 google kms 解密数据。由于某种原因,我无法成功解密数据,我只是得到一个空缓冲区作为响应。这是我的代码
app.post('/', (req, res) => {
var testToken = Buffer.from("test-token").toString('base64')
console.log("access token:" + testToken )
client.encrypt({name, testToken })
.then(responses => {
const response = responses[0];
//TRIED THIS
//const ciphertext = response.ciphertext
//AND THIS
const ciphertext = response.ciphertext.toString('base64')
console.log(ciphertext)
client.decrypt({name, ciphertext})
.then(responses2 => {
console.log(responses2);
console.log(Buffer.from(responses2[0].plaintext, 'base64').toString("utf8"))
return res.status(200).send({"status": "succes"})
})
.catch(err => {
console.log(err);
return res.status(400).send({"status": "error"})
});
})
.catch(err => {
console.log(err);
return res.status(400).send({"status": "error"})
});
});
这是我正在打印的日志
info: access token:dGVzdC10b2tlbg==
info: CiQAoYg0TZ0KIurHuDKRxNt5tBm+bWv94gjCRqJbzi/d8ZGk7k8SIQBZ//kUwUOpsnFquNYyxrd5w6YmUMlGupghjUsjf94G9g==
info: [ { plaintext: <Buffer > }, undefined, undefined ]
我想在不需要任何临时文件的情况下完成这项工作。提前致谢!