Class HmacSha256
- Namespace
- CryptoHives.Foundation.Security.Cryptography.Mac
- Assembly
- CryptoHives.Foundation.Security.Cryptography.dll
Computes the HMAC-SHA-256 message authentication code.
public sealed class HmacSha256 : HmacCore, IMac, IDisposable
- Inheritance
-
HmacSha256
- Implements
- Inherited Members
Examples
byte[] key = new byte[32]; // your secret key
byte[] data = Encoding.UTF8.GetBytes("Hello, World!");
using var hmac = HmacSha256.Create(key);
byte[] tag = hmac.ComputeHash(data);
Remarks
This is a fully managed implementation of HMAC-SHA-256 as defined in RFC 2104, using the CryptoHives SHA-256 implementation. It does not rely on OS or hardware cryptographic APIs, ensuring deterministic behavior across all platforms.
HMAC-SHA-256 produces a 256-bit (32-byte) authentication tag.
Constructors
HmacSha256(byte[])
Initializes a new instance of the HmacSha256 class.
public HmacSha256(byte[] key)
Parameters
keybyte[]The secret key.
Fields
MacSizeBits
The MAC output size in bits.
public const int MacSizeBits = 256
Field Value
MacSizeBytes
The MAC output size in bytes.
public const int MacSizeBytes = 32
Field Value
Methods
Create(byte[])
Creates a new instance of the HmacSha256 class.
public static HmacSha256 Create(byte[] key)
Parameters
keybyte[]The secret key.
Returns
- HmacSha256
A new HMAC-SHA-256 instance.
Hash(byte[], byte[])
Computes the HMAC-SHA-256 tag for the specified key and data in a single operation.
public static byte[] Hash(byte[] key, byte[] data)
Parameters
Returns
- byte[]
The 32-byte MAC tag.