Table of Contents

Class HashingContext

Namespace
Godot
Assembly
GodotSharp.dll

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.

public const int ChunkSize = 1024;

public void HashFile(string path) { // Check that file exists. if (!FileAccess.FileExists(path)) { return; } // Start a 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.EofReached()) { ctx.Update(file.GetBuffer(ChunkSize)); } // Get the computed hash. byte[] res = ctx.Finish(); // Print the result as hex string and array. GD.PrintT(res.HexEncode(), (Variant)res); }

public class HashingContext : RefCounted, IDisposable
Inheritance
HashingContext
Implements
Inherited Members

Constructors

HashingContext()

public HashingContext()

Methods

Finish()

Closes the current context, and return the computed hash.

public byte[] Finish()

Returns

byte[]

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

Start(HashType)

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

public Error Start(HashingContext.HashType type)

Parameters

type HashingContext.HashType

Returns

Error

Update(byte[])

Updates the computation with the given chunk of data.

public Error Update(byte[] chunk)

Parameters

chunk byte[]

Returns

Error