On this page
  1. hmac.new
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

hmac.new

Prev: hmac.HMAC | Up: hmac
Rel: hmac.compare_digest, hmac.digest, hmac.HMAC
Ref: docs.python.org — hmac.new
Tags: #public #python3 #stdlib #hmac


Import

import hmac
from hmac import new

Signature & Overview

hmac.new(key, msg=None, digestmod='')

Create a new hashing object and return it.

Usage

import hashlib
import hmac

mac = hmac.new(b"signing-key", digestmod=hashlib.sha256)
mac.update(b"part1")
mac.update(b"part2")
assert mac.digest() == hmac.digest(b"signing-key", b"part1part2", "sha256")

Gotchas

REPL Inspect

from hmac import new
help(new)

Linked from

Related notes