PRACTICAL 8: HMAC-SHA1

8.1 HMAC-SHA1 of a typed message

import hmac, hashlib

msg = input("Enter the message: ").encode()
key = input("Enter the secret key: ").encode()

print("HMAC-SHA1 Signature:", hmac.new(key, msg, hashlib.sha1).hexdigest())

8.2 HMAC-SHA1 of a text file

import hmac, hashlib

path = input("Enter the path of the text file: ")
key = input("Enter the secret key: ").encode()

with open(path, "rb") as f:
    print("HMAC-SHA1:", hmac.new(key, f.read(), hashlib.sha1).hexdigest())
