没有--密文文件的gcloud kms解密

gcloud kms decrypt without --ciphertext-file

我可以使用以下命令在没有 --ciphertext-file 文件路径的情况下进行加密

echo -n mytext | gcloud kms encrypt --plaintext-file=- \
 --ciphertext-file=- --location=xxxx --keyring=xxx \
 --key=xxxx | base64

上面的命令returns一个响应CiQALDSTqyFnlrxtK9phQqLb849IZTiIOvjsG2.....

现在我要解密CiQALDSTqyFnlrxtK9phQqLb849IZTiIOvjsG2.....

以下是我尝试过但对我不起作用的方法

echo -n CiQALDSTqyFnlrxtK9phQqLb849IZTiIOvjsG2..... | \
 gcloud kms decrypt --plaintext-file=- \
 --ciphertext-file=- --location=xxx --keyring=xxx \
 --key=xxx | base64

收到错误 ERROR: (gcloud.kms.decrypt) INVALID_ARGUMENT: Decryption failed: the ciphertext is invalid.

谢谢,任何帮助将不胜感激

第一个示例中的 base64 命令 编码 值。您必须 解码 第二个命令中的值:

echo -n CiQALDSTqyFnlrxtK9phQqLb849IZTiIOvjsG2..... | \
 base64 --decode | \
 gcloud kms decrypt --plaintext-file=- \
 --ciphertext-file=- --location=xxx --keyring=xxx \
 --key=xxx