我需要在 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
作为内部的行尾,但在最后一个 }
之后没有行尾括号。