Calculating a SHA hash with a string + secret key in python

前端 未结 5 618
我在风中等你
我在风中等你 2020-11-30 20:31

Amazon Product API now requires a signature with every request which I\'m trying to generate ushing Python.

The step I get hung up on is this one:

\"Calculat

5条回答
  •  春和景丽
    2020-11-30 20:53

    import hmac
    import hashlib
    import base64
    
    digest = hmac.new(secret, msg=thing_to_hash, digestmod=hashlib.sha256).digest()
    signature = base64.b64encode(digest).decode()
    

    I know this sounds silly, but make sure you don't have a trailing space on your secret by accident.

提交回复
热议问题