无法使用 google kms typescript/node 解密,结果为空

Unable to decrypt using google kms typescript/node, getting emtpy results

如有任何帮助,我们将不胜感激:)。我正在尝试创建一个 firebase 函数来使用 google 公里来解密数据。由于某种原因,我无法成功解密数据,我只是得到一个空缓冲区作为响应。这是我的代码

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 ]

我想在不需要任何临时文件的情况下完成这项工作。 提前致谢!

我发现了这个问题.. 以防其他人 运行 遇到这个问题,问题出在加密方法的第二个参数上,它必须像这样命名明文

client.encrypt({name, plaintext})

所以看起来 kms 正在加密空值,因为明文不存在,所以在解密时,它也返回了空值。

我认为在 api 级别添加某种警告或异常会很有用。