Calculate, store, and verify checksums on various occasions.
PM> Install-Package -Id Contrib.System.CheckSum -pre --source https://www.myget.org/F/dittodhole/api/v2
PM> Install-Package -Id Source.Contrib.System.CheckSum -pre --source https://www.myget.org/F/dittodhole/api/v2
PM> Install-Package -Id Contrib.System.CheckSum
PM> Install-Package -Id Source.Contrib.System.CheckSum
namespace Example1.CreateCheckSumForString
{
using global::System;
using global::Contrib.System.CheckSum;
public static void Main(params string[] args)
{
var stringCheckSumCalculator = new StringCheckSumCalculator();
var input = "hello";
var checkSum = stringCheckSumCalculator.CalculateCheckSum(input);
}
}
namespace Example2.InjectHashAlgorithm
{
using global::System;
using global::System.Security.Cryptography;
using global::Contrib.System.CheckSum;
public static void Main(params string[] args)
{
var stringCheckSumCalculator = new StringCheckSumCalculator(MD5.Create); // default is MD5
stringCheckSumCalculator = new StringCheckSumCalculator(SHA1.Create);
stringCheckSumCalculator = new StringCheckSumCalculator(SHA256.Create);
var input = "hello";
var checkSum = stringCheckSumCalculator.CalculateCheckSum(input);
}
}
namespace Example3.CreateCheckSumForSequence
{
using global::System;
using global::Contrib.System.CheckSum;
public static void Main(params string[] args)
{
var stringCheckSumCalculator = new StringCheckSumCalculator();
var sequenceCheckSumCalculator = new SequenceCheckSumCalculator(stringCheckSumCalculator);
var input = new[] { "hello", "foo", "bar" };
var checkSum = sequenceCheckSumCalculator.CalculateCheckSum(input);
}
}
namespace Example4.CreateCheckSumForDictionary
{
using global::System;
using global::System.Collections.Generic;
using global::Contrib.System.CheckSum;
public static void Main(params string[] args)
{
var stringCheckSumCalculator = new StringCheckSumCalculator();
var sequenceCheckSumCalculator = new SequenceCheckSumCalculator(stringCheckSumCalculator);
var dictionaryCheckSumCalculator = new DictionaryCheckSumCalculator(sequenceCheckSumCalculator);
var input = new Dictionary<string, string>
{
{ "entry1", "hello" },
{ "entry2", "foo" },
{ "entry3", "bar" }
};
var checkSum = dictionaryCheckSumCalculator.CalculateCheckSum(input);
}
}
namespace Example5.CreateCheckSumForDictionaryExtended
{
using global::System;
using global::System.Collections.Generic;
using global::Contrib.System.CheckSum;
public static void Main(params string[] args)
{
var stringCheckSumCalculator = new StringCheckSumCalculator();
var sequenceCheckSumCalculator = new SequenceCheckSumCalculator(stringCheckSumCalculator);
var dictionaryCheckSumCalculatorEx = new DictionaryCheckSumCalculatorEx(sequenceCheckSumCalculator)
{
CheckSumKey = "CRC"
};
var input = new Dictionary<string, string>
{
{ "entry1", "hello" },
{ "entry2", "foo" },
{ "entry3", "bar" },
{ "CRC", string.Empty } // this key will be ignored by the following calculations
};
var checkSum = dictionaryCheckSumCalculatorEx.CalculateCheckSum(input);
checkSum = dictionaryCheckSumCalculatorEx.CalculateAndStoreCheckSum(input);
checkSum = dictionaryCheckSumCalculatorEx.GetStoredCheckSum(input);
var isValid = dictionaryCheckSumCalculatorEx.IsStoredCheckSumValid(input);
}
}
namespace Example6.CreateCheckSumForObject
{
using global::Contrib.System.CheckSum;
public class Input
{
public string Entry1 { get; set; }
public string Entry2 { get; set; }
public string Entry3 { get; set; }
}
public static void Main(params string[] args)
{
var stringCheckSumCalculator = new StringCheckSumCalculator();
var sequenceCheckSumCalculator = new SequenceCheckSumCalculator(stringCheckSumCalculator);
var objectCheckSumCalculator = new ObjectCheckSumCalculator(sequenceCheckSumCalculator);
var input = new Input
{
Entry1 = "hello",
Entry2 = "foo",
Entry3 = "bar"
};
var checkSum = objectCheckSumCalculator.CalculateCheckSum(input);
}
}
namespace Example7.CreateCheckSumForObjectExtended
{
using global::System;
using global::Contrib.System.CheckSum;
public class Input
{
public string Entry1 { get; set; }
public string Entry2 { get; set; }
public string Entry3 { get; set; }
public string CheckSum { get; set; }
}
public static void Main(params string[] args)
{
var stringCheckSumCalculator = new StringCheckSumCalculator();
var sequenceCheckSumCalculator = new SequenceCheckSumCalculator(stringCheckSumCalculator);
var objectCheckSumCalculatorEx = new ObjectCheckSumCalculatorEx(sequenceCheckSumCalculator)
{
CheckSumPropertyName = nameof(Input.CheckSum) // this property will be ignored by the following calculations
};
var input = new Input
{
Entry1 = "hello",
Entry2 = "foo",
Entry3 = "bar",
CheckSum = string.Empty
};
var checkSum = objectCheckSumCalculatorEx.CalculateCheckSum(input);
checkSum = objectCheckSumCalculatorEx.CalculateAndStoreCheckSum(input);
checkSum = objectCheckSumCalculatorEx.GetStoredCheckSum(input);
var isValid = objectCheckSumCalculatorEx.IsStoredCheckSumValid(input);
}
}
> git clone https://github.com/dittodhole/dotnet-Contrib.System.CheckSum.git
> cd dotnet-Contrib.System.CheckSum/
dotnet-Contrib.System.CheckSum> cd build
dotnet-Contrib.System.CheckSum/build> build.bat
This will create dotnet-Contrib.System.CheckSum/artifacts/Contrib.System.CheckSum.{version}.nupkg
.
dotnet-Contrib.System.CheckSum is published under WTFNMFPLv3.