34 lines
904 B
C#
34 lines
904 B
C#
using System.Security.Cryptography;
|
|
|
|
namespace MfGames.Cryptography.Hashes;
|
|
|
|
public static class HashTypeExtensions
|
|
{
|
|
/// <summary>
|
|
/// Constructs a hash of the given type.
|
|
/// </summary>
|
|
/// <param name="type">The type of hash to create.</param>
|
|
/// <returns>A hash algorithm of the given type.</returns>
|
|
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
|
public static HashAlgorithm CreateHash(this HashType type)
|
|
{
|
|
switch (type)
|
|
{
|
|
case HashType.Sha512:
|
|
return SHA512.Create();
|
|
|
|
case HashType.Sha256:
|
|
return SHA256.Create();
|
|
|
|
case HashType.Sha1:
|
|
return SHA1.Create();
|
|
|
|
case HashType.Md5:
|
|
return MD5.Create();
|
|
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
|
}
|
|
}
|
|
}
|