【问题标题】:Unable to decrypt using google kms typescript/node, getting emtpy results无法使用 google kms typescript/node 解密,得到 emtpy 结果
【发布时间】:2019-02-15 03:09:48
【问题描述】:

对此的任何帮助将不胜感激:)。我正在尝试创建一个 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 ]

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

【问题讨论】:

    标签: google-cloud-platform google-cloud-kms


    【解决方案1】:

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

    client.encrypt({name, plaintext})
    

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

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

    【讨论】:

      猜你喜欢
      • 2018-01-23
      • 2019-03-08
      • 1970-01-01
      • 2017-09-20
      • 2018-07-09
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多