Skip to content

Instantly share code, notes, and snippets.

@LowerDeez
Forked from gauravvjn/create_sha256_signature.py
Last active October 3, 2019 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LowerDeez/0ec0b3f780d7ae8b26def58f5872a0c5 to your computer and use it in GitHub Desktop.
Save LowerDeez/0ec0b3f780d7ae8b26def58f5872a0c5 to your computer and use it in GitHub Desktop.
Create HMAC SHA256 signature/encryption/encode
"""
https://gist.github.com/Azadehkhojandi/50eaae4cf20b21faef186f2c8ee97873
"""
import hmac
import hashlib
import binascii
# 1
def create_sha256_signature(key, message):
"""
"""
byte_key = binascii.unhexlify(key)
message = message.encode()
return hmac.new(byte_key, message, hashlib.sha256).hexdigest().upper()
key = "E49756B4C8FAB4E48222A3E7F3B97CC3"
message = "TEST STRING"
create_sha256_signature(key, message)
# 2
def create_sha256_signature(key: str, message: str):
message = message.encode()
return (
hmac.new(str.encode(key), message, hashlib.sha256).hexdigest().upper()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment