Skip to content

Commit a5f282c

Browse files
authored
Hmac verification (#87)
* adding hmac valdiation example code * comments
1 parent 6e5ab8f commit a5f282c

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

connect_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def validateHMAC():
2+
import hmac
3+
import hashlib
4+
import base64
5+
file = open("payload.txt", "rb") # Read the payload from a file named payload.txt
6+
payload = file.read()
7+
secret = "4+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxuE=" # Replace this value with your own secret
8+
signature = "e4xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxhg=" # Replace this value with your own signature
9+
10+
hashBytes = hmac.new(str.encode(secret), msg=payload, digestmod=hashlib.sha256).digest()
11+
base64Hash = base64.b64encode(hashBytes)
12+
return hmac.compare_digest(str.encode(signature), base64Hash)
13+
14+
print(validateHMAC())

0 commit comments

Comments
 (0)