ChecksumBuilder Class
Definition
- Assemblies
- Cuemon.Data.Integrity.dll
Provides a way to fluently represent checksum values of arbitrary data.
public class ChecksumBuilder : IDataIntegrity, IEquatable<ChecksumBuilder>
- Inheritance
-
ChecksumBuilder
- Implements
- Derived
Examples
The following example demonstrates how to use ChecksumBuilder to compute and compare checksums for arbitrary data.
using System;
using System.Text;
using Cuemon.Data.Integrity;
using Cuemon.Security;
namespace MyApp.Examples
{
public sealed class ChecksumBuilderExample
{
public void Demonstrate()
{
var builder = new ChecksumBuilder(() => HashFactory.CreateFnv128());
Console.WriteLine($"Empty checksum: {builder.Checksum.ToHexadecimalString()}");
builder.CombineWith(BitConverter.GetBytes(42L));
builder.CombineWith(Encoding.UTF8.GetBytes("Hello, World!"));
var comparison = new ChecksumBuilder(BitConverter.GetBytes(42L), () => HashFactory.CreateFnv128());
comparison.CombineWith(Encoding.UTF8.GetBytes("Hello, World!"));
Console.WriteLine($"Current checksum: {builder}");
Console.WriteLine($"Checksums match: {builder.Equals(comparison)}");
Console.WriteLine($"Hash code: {builder.GetHashCode()}");
}
}
}
Constructors
| Name | Description |
|---|---|
| ChecksumBuilder(byte[], Func<Hash>) | Initializes a new instance of the ChecksumBuilder class. |
| ChecksumBuilder(Func<Hash>) | Initializes a new instance of the ChecksumBuilder class. |
Properties
| Name | Description |
|---|---|
| Bytes | Gets a byte array that is the result of the associated ChecksumBuilder. |
| Checksum | Gets a HashResult containing a computed hash value of the data this instance represents. |
| ComputedHash | Gets or sets the computed checksum of Bytes. |
| HashFactory | Gets the value factory of this instance. |
Methods
| Name | Description |
|---|---|
| CombineWith(byte[]) | Combines the |
| Equals(ChecksumBuilder) | Indicates whether the current object is equal to another object of the same type. |
| Equals(object) | Determines whether the specified Object is equal to this instance. |
| GetHashCode() | Returns a hash code for this instance. |
| ToString() | Converts the the Bytes of this instance to its equivalent hexadecimal representation. |