
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
hmac2
Advanced tools
The HMAC class implements an HMAC (Hash-based Message Authentication Code) using a specified hash function. It provides a simple interface to generate HMAC values using a key and a hash algorithm like SHA256, MD5, etc.
from hmac2 import HMAC
# Define a key and a message
key = b'secret_key'
message = b'my message'
# Create a new HMAC instance with the key, message, and hash algorithm
h = HMAC(key, message, digestmod='sha256')
If you need to add more data to the existing HMAC computation:
h.update(b' additional message')
# Get the HMAC value in hexadecimal format
print(h.hexdigest())
# Alternatively, get the raw binary value
print(h.digest())
__init__(self, key, msg=None, digestmod='sha256')
Initializes an HMAC instance with a given key, an optional message, and a digest algorithm. The default digest algorithm is 'sha256'.
update(self, msg)
Updates the HMAC object with more message bytes. You can call this method multiple times with different parts of the message.
digest(self)
Returns the raw HMAC value as a byte sequence.
hexdigest(self)
Returns the HMAC value as a hexadecimal string.
new FunctionYou can also use the new function for a more concise syntax:
import hmac2
# Define a key and a message
key = b'secret_key'
message = b'my message'
# Create a new HMAC and get the result in hex format
hmac_value = hmac2.new(key, message, 'sha256').hexdigest()
print("HMAC: ", hmac_value)
FAQs
A small test package for hmac2.
We found that hmac2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.