Postgresql hmac-sha1签名与python签名不同

时间:2014-08-18 08:01:52

标签: python postgresql amazon-s3 plpgsql hmac

的Postgres

代码:

SELECT encode(
    hmac(
        E'PUT\n\n1\n1408355972\nx-amz-acl:bucket-owner-full-control\n/1/1', 
        '1sf235123',
        'sha1'
    ),
    'base64'
);

结果:"h9wRL15mXgwRxXjqLqhbYbnfJ7I="

Python 3

代码:

base64.encodestring(
    hmac.new(
        'PUT\n\n1\n1408355972\nx-amz-acl:bucket-owner-full-control\n/1/1'.encode(),
        '1sf235123'.encode(),
        sha1
    ).digest()
)

结果:"CrU1V93ggf3QE0ovq686ir/i1ss=\n"

我想在postgres中签署s3上传请求,但我无法获得正确的签名,我已经尝试了一整天T_T。

有人能帮我一个忙吗?非常感谢。

1 个答案:

答案 0 :(得分:2)

您正在Python中交换两个第一个hmac参数。 hmac构造函数首先获取秘密

>>> base64.encodestring(
...     hmac.new(
...         '1sf235123'.encode(),
...         'PUT\n\n1\n1408355972\nx-amz-acl:bucket-owner-full-control\n/1/1'.encode(),
...         sha1
...     ).digest()
... )
b'h9wRL15mXgwRxXjqLqhbYbnfJ7I=\n'
相关问题