HmacContext
Used to create an HMAC for a message using a key.
Used to create an HMAC for a message using a key.
The HMACContext class is useful for advanced HMAC use cases, such as streaming the message as it supports creating the message over time rather than providing it all at once.
using Reckfell;
using System.Diagnostics;
public partial class MyNode : Entity
{
private HmacContext _ctx = new HmacContext();
public override void _Ready()
{
byte[] key = "supersecret".ToUtf8Buffer();
Error err = _ctx.Start(HashingContext.HashType.Sha256, key);
Debug.Assert(err == Error.Ok);
byte[] msg1 = "this is ".ToUtf8Buffer();
byte[] msg2 = "super duper secret".ToUtf8Buffer();
err = _ctx.Update(msg1);
Debug.Assert(err == Error.Ok);
err = _ctx.Update(msg2);
Debug.Assert(err == Error.Ok);
byte[] hmac = _ctx.Finish();
ReckfellApi.Print(hmac.HexEncode());
}
}Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
HmacContextConstructor
public HmacContext();Methods5
Finishbyte[]
Start2 overloads
public Error Start(HashingContext.HashType hashType, byte[] key);Initializes the HMACContext. This method cannot be called again on the same HMACContext until HmacContext.Finish has been called.
| Name | Type | Default |
|---|---|---|
hashType | HashingContext.HashType | — |
key | byte[] | — |
Errorpublic Error Start(HashingContext.HashType hashType, ReadOnlySpan<byte> key);Initializes the HMACContext. This method cannot be called again on the same HMACContext until HmacContext.Finish has been called.
| Name | Type | Default |
|---|---|---|
hashType | HashingContext.HashType | — |
key | ReadOnlySpan<byte> | — |
ErrorUpdate2 overloads
public Error Update(byte[] data);Updates the message to be HMACed. This can be called multiple times before HmacContext.Finish is called to append data to the message, but cannot be called until HmacContext.Start has been called.
| Name | Type | Default |
|---|---|---|
data | byte[] | — |
Errorpublic Error Update(ReadOnlySpan<byte> data);Updates the message to be HMACed. This can be called multiple times before HmacContext.Finish is called to append data to the message, but cannot be called until HmacContext.Start has been called.
| Name | Type | Default |
|---|---|---|
data | ReadOnlySpan<byte> | — |
Error