reckfellENGINE

HmacContext

Used to create an HMAC for a message using a key.

On this page
class HmacContextReckfellSharpInherits RefCounted

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.

C#
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
# HmacContext
C#
public HmacContext();

Methods5

Finishbyte[]
# Finish
C#
public byte[] Finish();

Returns the resulting HMAC. If the HMAC failed, an empty byte[] is returned.

Returns byte[]
Start2 overloads
# Start · 1/2
C#
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.

Parameters
NameTypeDefault
hashTypeHashingContext.HashType—
keybyte[]—
Returns Error
# Start · 2/2
C#
public 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.

Parameters
NameTypeDefault
hashTypeHashingContext.HashType—
keyReadOnlySpan<byte>—
Returns Error
Update2 overloads
# Update · 1/2
C#
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.

Parameters
NameTypeDefault
databyte[]—
Returns Error
# Update · 2/2
C#
public 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.

Parameters
NameTypeDefault
dataReadOnlySpan<byte>—
Returns Error
Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.