在 c++ 中为 google 桶上传签名 URL

Signing URL in c++ for google bucket upload

我需要在 C++ 中使用 cURL 将图像上传到 google 云存储桶。 google 未根据他们的 example and pseudo code 提供 c++ sdk support.As 我们必须执行以下过程;

Blockquote

   Policy = Base-64-Encoding-Of(PolicyDocument)
   MessageDigest = SHA256withRSA(SecretKey, Policy)
   Signature = Base64-Encoding-Of(MessageDigest)

按照他们的流程,我已经完成了base64编码,但是我找不到任何东西如何执行SHA256withRSA? 请帮助我使用 c++ 中的 SHA256withRSA。

您可以使用 openssl 库或通常与它打包的命令行实用程序生成这样的签名。

据我所知,我从未使用过 Google Cloud Platform,只是想扩展他们的文档,要手动完成此操作,您需要

1) 您的 Google 云凭据的 .pem 版本。让我们称之为 private.pem

使用 https://cloud.google.com/storage/docs/authentication#converting-the-private-key

中显示的过程

2) 政策文件。按照原始 URL

中给出的示例,使用文本编辑器创建它
 vi policy.txt

3) 该策略文档的 base64 编码。使用 Linux 工具 base64 来制作它。你会从中得到一长串。让我们称之为STRINGA。假设它保存在 STRINGA.txt

base64 < policy.txt > STRINGA.txt

4) 从 STRINGA

生成的签名

openssl sha -sha256 -sign private.pem < STRINGA.txt | base64 >SIGNED.txt

5) 从包含

的 html 表单中执行 POST
<input type="hidden" name="policy" value="Put STRINGA string here">
<input type="hidden" name="signature" value="Put SIGNED string here">

类似于您在原始 URL

中作为示例给出的内容

https://cloud.google.com/storage/docs/xml-api/post-object#usage_and_examples

我从他们的 HTML 代码中获取了他们的示例 base64 编码策略文档,并感兴趣地注意到他们使用 \r\n 作为内部的行尾,但在最后的 }括号.