test_hmac.py 387 B

12345678910111213141516
  1. import hmac
  2. secret = "0123456789"
  3. payload = "helloworld"
  4. h = hmac.new(secret.encode(),digestmod="md5")
  5. h.update(payload.encode())
  6. print("hmac-md5:",h.hexdigest())
  7. h = hmac.new(secret.encode(),digestmod="sha1")
  8. h.update(payload.encode())
  9. print("hmac-sha1:",h.hexdigest())
  10. h = hmac.new(secret.encode(),digestmod="sha256")
  11. h.update(payload.encode())
  12. print("hmac-sha256:",h.hexdigest())