c++ - 在 C++ 中为谷歌存储桶上传签名 URL

标签 c++ rsa google-cloud-storage sha256 signing

<分区>

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

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) .pem您的 Google Cloud 凭据的版本。让我们称之为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">

类似于您在原始网址中作为示例给出的内容

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

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

关于c++ - 在 C++ 中为谷歌存储桶上传签名 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37619638/

相关文章:

c++ - 将递归更改为更便宜的东西

java - 我在执行解密时遇到基数超出范围异常

c# - 将 C# RSACryptoServiceProvider 翻译成 JAVA 代码

amazon-s3 - GSUtil rsync 在 S3 存储桶上给出 400 不可​​重试异常

c++ - 二维数组错误: Vector index beyond memory allocation

c++ - ifdef : is "#ifdef A && B" the same as "#if defined(A) && defined(B)"? 中的 bool 值

c++ - 这里有循环依赖吗?

python - 如何在python中使用RSA私钥加密数据?

node.js - 如何使用node.js在firebase中存储文件

linux - 谷歌云存储桶: Mounting in a Linux instance with Global Permissions