reckfellENGINE

HashingContext

Provides functionality for computing cryptographic hashes chunk by chunk.

On this page
class HashingContextReckfellSharpInherits RefCounted

Provides functionality for computing cryptographic hashes chunk by chunk.

The HashingContext class provides an interface for computing cryptographic hashes over multiple iterations. Useful for computing hashes of big files (so you don't have to load them all in memory), network streams, and data streams in general (so you don't have to hold buffers). The HashingContext.HashType enum shows the supported hashing algorithms.

C#
public const int ChunkSize = 1024;

public void HashFile(string path)
{
    // Check that file exists.
    if (!FileAccess.FileExists(path))
    {
        return;
    }
    // Start an SHA-256 context.
    var ctx = new HashingContext();
    ctx.Start(HashingContext.HashType.Sha256);
    // Open the file to hash.
    using var file = FileAccess.Open(path, FileAccess.ModeFlags.Read);
    // Update the context after reading each chunk.
    while (file.GetPosition() < file.GetLength())
    {
        int remaining = (int)(file.GetLength() - file.GetPosition());
        ctx.Update(file.GetBuffer(Mathf.Min(remaining, ChunkSize)));
    }
    // Get the computed hash.
    byte[] res = ctx.Finish();
    // Print the result as hex string and array.
    ReckfellApi.PrintT(res.HexEncode(), (Variant)res);
}

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

HashingContextConstructor
# HashingContext
C#
public HashingContext();

Methods4

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

Closes the current context, and return the computed hash.

Returns byte[]
StartError
# Start
C#
public Error Start(HashingContext.HashType type);

Starts a new hash computation of the given type (e.g. HashingContext.HashType.Sha256 to start computation of an SHA-256).

Parameters
NameTypeDefault
typeHashingContext.HashType—
Returns Error
Update2 overloads
# Update · 1/2
C#
public Error Update(byte[] chunk);

Updates the computation with the given chunk of data.

Parameters
NameTypeDefault
chunkbyte[]—
Returns Error
# Update · 2/2
C#
public Error Update(ReadOnlySpan<byte> chunk);

Updates the computation with the given chunk of data.

Parameters
NameTypeDefault
chunkReadOnlySpan<byte>—
Returns Error

HashingContext.HashType

ValueDescription
Md5 = 0

Hashing algorithm: MD5.

Sha1 = 1

Hashing algorithm: SHA-1.

Sha256 = 2

Hashing algorithm: SHA-256.

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.