Class HashGenerator
Used to generate a string hash using crypto libraries over multiple objects
Namespace: Umbraco.Cms.Core
Assembly: Umbraco.Core.dll
Syntax
public class HashGenerator : DisposableObjectSlim
Remarks
This should be used to generate a reliable hash that survives AppDomain restarts. This will use the crypto libs to generate the hash and will try to ensure that strings, etc... are not re-allocated so it's not consuming much memory.
Constructors
View SourceHashGenerator()
Initializes a new instance of the HashGenerator class.
Declaration
public HashGenerator()
Methods
View SourceAddCaseInsensitiveString(string)
Adds a string to the hash computation in a case-insensitive manner.
Declaration
public void AddCaseInsensitiveString(string s)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The string to add. If null, nothing is added. |
Remarks
The string is converted to uppercase before being added to ensure case-insensitive hash generation.
AddDateTime(DateTime)
Adds a DateTime value to the hash computation using its ticks.
Declaration
public void AddDateTime(DateTime d)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | d | The DateTime value to add. |
AddFile(FileInfo)
Adds a file to the hash computation.
Declaration
public void AddFile(FileInfo f)
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo | f | The file to add. |
AddFileSystemItem(FileSystemInfo)
Adds a file system item (file or directory) to the hash computation.
Declaration
public void AddFileSystemItem(FileSystemInfo f)
Parameters
| Type | Name | Description |
|---|---|---|
| FileSystemInfo | f | The file system item to add. |
Remarks
For files, adds the full name, creation time, last write time, and length. For directories, recursively adds all files and subdirectories.
AddFolder(DirectoryInfo)
Adds a folder and its contents to the hash computation.
Declaration
public void AddFolder(DirectoryInfo d)
Parameters
| Type | Name | Description |
|---|---|---|
| DirectoryInfo | d | The directory to add. |
AddInt(int)
Adds an integer value to the hash computation.
Declaration
public void AddInt(int i)
Parameters
| Type | Name | Description |
|---|---|---|
| int | i | The integer value to add. |
AddLong(long)
Adds a long value to the hash computation.
Declaration
public void AddLong(long i)
Parameters
| Type | Name | Description |
|---|---|---|
| long | i | The long value to add. |
AddObject(object)
Adds an object's string representation to the hash computation.
Declaration
public void AddObject(object o)
Parameters
| Type | Name | Description |
|---|---|---|
| object | o | The object to add. |
AddString(string)
Adds a string to the hash computation.
Declaration
public void AddString(string s)
Parameters
| Type | Name | Description |
|---|---|---|
| string | s | The string to add. If null, nothing is added. |
DisposeResources()
Disposes managed resources
Declaration
protected override void DisposeResources()
GenerateHash()
Returns the generated hash of all added objects.
Declaration
public string GenerateHash()
Returns
| Type | Description |
|---|---|
| string | A hexadecimal string representation of the computed hash. |
Remarks
Uses SHA1 when FIPS compliance is required, otherwise uses MD5. This method can be called multiple times; subsequent calls will include any objects added after the previous call.