Postgresql hmac-sha1 签名与 Python 签名不同
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 个回答
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'