Skip to content

Commit d3e9e09

Browse files
authored
Add more examples to README
Signed-off-by: Xen <lordofxen@deskasoft.com>
1 parent 37b70f7 commit d3e9e09

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

README.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ IHashFunctionBase[] functions = HashFactory.CreateHashAlgorithms(HashFunctionTyp
219219

220220
foreach (IHashFunctionBase function in functions)
221221
{
222-
IHashValue hv = function.ComputeHash("foobar");
223-
// Use the computed hash here...
222+
IHashValue computedHash = function.ComputeHash("foobar");
223+
Console.WriteLine(computedHash.AsHexString());
224224
}
225225
```
226226

@@ -236,7 +236,9 @@ IHashFunctionBase[] functions = HashFactory.CreateHashAlgorithms(HashFunctionTyp
236236
237237
foreach (IHashFunctionBase function in functions)
238238
{
239-
IHashValue hv = function.ComputeHash("foobar");
239+
IHashValue computedHash = function.ComputeHash("foobar");
240+
241+
Console.WriteLine(computedHash.AsHexString());
240242

241243
// This ensures that we only try disposing of cryptographic hashes.
242244
if (function is ICryptographicHashFunctionBase cryptoHash)
@@ -246,6 +248,33 @@ foreach (IHashFunctionBase function in functions)
246248
}
247249
```
248250

251+
### Example computing all hashes then finding the safest result for our input:
252+
``` CSharp
253+
IHashFunctionBase[] functions = HashFactory.CreateHashAlgorithms(HashFunctionType.Noncryptographic | HashFunctionType.Cryptographic, new Dictionary<Type, IHashConfigBase>()
254+
{
255+
256+
// Only adding configs that require us to pick or define one, for the rest of the hash algorithms, the default provided configs will be used instead.
257+
{ typeof(ICRC), new CRCConfigProfileCRC32() },
258+
{ typeof(IPearson), new PearsonConfigProfileWikipedia() },
259+
{ typeof(IFNV1), new FNVConfigProfile32Bits()},
260+
{ typeof(IFNV1a), new FNVConfigProfile32Bits() },
261+
{ typeof(IBuzHash), new BuzHashConfigProfileDefault() },
262+
263+
{ typeof(IArgon2id), new Argon2idConfigProfileOWASP() }
264+
265+
});
266+
267+
Dictionary<Type, IHashValue> hashValues = new();
268+
foreach (IHashFunctionBase function in functions)
269+
{
270+
IHashValue computedHash = function.ComputeHash("foobar");
271+
hashValues.Add(function.GetType(), computedHash);
272+
}
273+
274+
KeyValuePair<Type, IHashValue> safestHash = hashValues.MaxBy(t => t.Value.CalculateEntropy())!;
275+
Console.WriteLine($"Safest Hash Value for 'foobar' is '{safestHash.Key.Name}': {safestHash.Value.AsHexString()}");
276+
```
277+
249278
A significant number of additional modifications have been implemented within the library. We encourage you to integrate these updates into your project and explore them fully.
250279
We are eager to observe the innovative applications you develop, or have already developed, using our library. Please feel free to share your work with us by joining our community at: https://discord.gg/PrKery9.
251280

@@ -284,3 +313,4 @@ License
284313
HashifyNET is released under the terms of the MIT license. See [LICENSE](https://github.com/deskasoft/HashifyNET/blob/master/LICENSE) for more information or see http://opensource.org/licenses/MIT.
285314

286315

316+

0 commit comments

Comments
 (0)