logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class HashUtils

    Utility class for hashing bytes into a stable, printable form.

    Inheritance
    object
    HashUtils
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.Shared.Utils
    Assembly: Serenity.Shared.dll
    Syntax
    public static class HashUtils

    Methods

    Sha256Hex(byte[], int?)

    Hashes bytes with SHA-256 and returns the digest — or a leading slice of it — as lowercase hex.

    Declaration
    public static string Sha256Hex(byte[] bytes, int? byteCount = null)
    Parameters
    Type Name Description
    byte[] bytes

    The bytes to hash.

    int? byteCount

    How many leading digest bytes to render as hex, or null for the full 32-byte digest. A caller that only needs a short, collision-tolerant suffix or lock name (never persisted identity spanning a full digest) can ask for fewer; clamped to the digest's own length when larger.

    Returns
    Type Description
    string

    The digest hex — 64 lowercase characters for the default full digest, or byteCount * 2 when given — or empty when bytes is null.

    In this article
    © 2026 Serenity. All Rights Reserved