开发者社区> 问答> 正文

php sdk中为何验证串和文档的不同?

测试源码:
$signStr = "PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu,  17  Nov  2005  18:49:58 GMT\nx-oss-magic:abracadabra\nx-oss-meta-author:foo@bar.com\n /quotes/nelson";
$access_key = "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV";
$test=base64_encode(hash_hmac('sha1', $signStr, $access_key, true));
echo "{$test}";

文档中结果为:63mwfl zYIOG6k95yxbgMruQ6QI=
实际结果总与文档不符,为何?

展开
收起
xu2004jie 2012-04-19 20:01:55 10192 0
2 条回答
写回答
取消 提交回答
  • 您好~   感谢您对OSS服务的关注, 也谢谢您关于API提出的问题。

    我发现~在您提供的$signStr这个字符串中 在x-oss-meta-author:foo@bar.com\n 和 /quotes/nelson之间,   多了一个空格。删除即可。

    请您用我这个串试试,   验证结果与API文档是一致的。
    $signStr = "PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu,  17  Nov  2005  18:49:58 GMT\nx-oss-magic:abracadabra\nx-oss-meta-author:foo@bar.com\n/quotes/nelson";


    2012-04-22 15:58:17
    赞同 展开评论 打赏
  • 这个是API文档中示例,和前面规则不一致.服了
    例如:想签名以下信息:
    PUT /quotes/nelson HTTP/1.0
    Content-Md5: c8fdb181845a4ca6b8fec737b3581d76
    Content-Type: text/html
    Date: Thu, 17 Nov 2005 18:49:58 GMT
    X-OSS-Meta-Author: foo@bar.com
    X-OSS-Magic: abracadabra
    假如 AccessID 是: "44CF9590006BF252F707"
    AccessKey 是 "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV",可用以下
    方法签名
    python 示例代码:
    import base64
    import hmac
    import sha
    h = hmac.new("OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV",
                              "PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu,  17  Nov  2005  18:49:58
    GMT\nx-oss-magic:abracadabra\nx-oss-meta-author:foo@bar.com\n
    /quotes/nelson", sha)
    base64.encodestring(h.digest()).strip()
    签名计算结果应该为”63mwfl zYIOG6k95yxbgMruQ6QI=”, 然后加上
    Authorization 头来组成最后需要发送的消息:
    PUT /quotes/nelson HTTP/1.0
    Authorization: OSS 44CF9590006BF252F707: 63mwfl zYIOG6k95yxbgMruQ6QI=
    Content-Md5: c8fdb181845a4ca6b8fec737b3581d76
    Content-Type: text/html
    Date: Thu, 17 Nov 2005 18:49:58 GMT
    X-OSS-Meta-Author: foo@bar.com
    X-OSS-Magic: abracadabra

    -------------------------

    谢谢解答,问题已经解决.

    2012-04-20 11:09:52
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载
复杂PHP系统性能瓶颈排查及优化 立即下载