For the complete documentation index, see llms.txt. This page is also available as Markdown.

Hash-based Message Authentication Code (HMAC)

Overview

This page contains recommendations for using a Hash-based message authentication code (HMAC).

General

Hash algorithm
Block size, bytes

SHA-256

64

SHA-512

128

SHA3-256

136

SHA3-512

72

  • You can use HMAC to check the integrity (signature) of messages between internal systems.

  • Do not use HMAC to integrate with a third-party system, use digital signatures.

  • Use HMAC based on hash algorithms from the SHA-2 family.

HMAC implementation

Use the crypto/hmac package to calculate HMAC in Go.

Use the javax.crypto.Mac class to calculate HMAC. You can find supported Mac algorithms at Java Security Standard Algorithm Names: Mac Algorithms.

Use the crypto package to calculate HMAC.

Use the hmac package to calculate HMAC. Use hmac.compare_digest function instead of the == operator to compare digests. Using hmac.compare_digest reduces the vulnerability to timing attacks.

Last updated