diff --git a/BarbezDotEu.Byte/BarbezDotEu.Byte/BarbezDotEu.Byte.csproj b/BarbezDotEu.Byte/BarbezDotEu.Byte/BarbezDotEu.Byte.csproj index 0b322fe..0d3297d 100644 --- a/BarbezDotEu.Byte/BarbezDotEu.Byte/BarbezDotEu.Byte.csproj +++ b/BarbezDotEu.Byte/BarbezDotEu.Byte/BarbezDotEu.Byte.csproj @@ -6,8 +6,8 @@ BarbezDotEu.Byte BarbezDotEu.Byte BarbezDotEu.Byte - ©2022 Hannes Barbez - 2.1.0 + ©2023 Hannes Barbez + 2.2.0 Generic logic pertaining to byte and byte arrays. byte, byte array true diff --git a/BarbezDotEu.Byte/BarbezDotEu.Byte/CryptoHelper.cs b/BarbezDotEu.Byte/BarbezDotEu.Byte/CryptoHelper.cs new file mode 100644 index 0000000..db82c6c --- /dev/null +++ b/BarbezDotEu.Byte/BarbezDotEu.Byte/CryptoHelper.cs @@ -0,0 +1,26 @@ +// Copyright (c) Hannes Barbez. All rights reserved. +// Licensed under the GNU General Public License v3.0 + +using System.Security.Cryptography; +using System.Text; + +namespace BarbezDotEu.Byte +{ + /// + /// Helpers for cryptography. + /// + public static class CryptoHelper + { + /// + /// Equivalent of T-SQL's HASHBYTES('SHA2_256', <toHash>)". + /// + /// The string to hash. + /// The result of the hash. + public static byte[] GetTsqlLikeHashBytes(string toHash) + { + byte[] hashable = Encoding.Unicode.GetBytes(toHash); + var hasher = SHA256.Create(); + return hasher.ComputeHash(hashable); + } + } +}