Returns a base64-encoded HMAC-SHA1 signature of a given string. :param secret: The key used for the signature, base64 encoded. :type secret: string :param payload: The payload to sign. :type payload: string :rtype: string
(secret, payload)
| 475 | |
| 476 | |
| 477 | def sign_hmac(secret, payload): |
| 478 | """Returns a base64-encoded HMAC-SHA1 signature of a given string. |
| 479 | |
| 480 | :param secret: The key used for the signature, base64 encoded. |
| 481 | :type secret: string |
| 482 | |
| 483 | :param payload: The payload to sign. |
| 484 | :type payload: string |
| 485 | |
| 486 | :rtype: string |
| 487 | """ |
| 488 | payload = payload.encode('ascii', 'strict') |
| 489 | secret = secret.encode('ascii', 'strict') |
| 490 | sig = hmac.new(base64.urlsafe_b64decode(secret), payload, hashlib.sha1) |
| 491 | out = base64.urlsafe_b64encode(sig.digest()) |
| 492 | return out.decode('utf-8') |
| 493 | |
| 494 | |
| 495 | def urlencode_params(params): |