Skip to content

Commit

Permalink
CryptoHelper.GetTsqlLikeHashBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesbarbez committed Feb 3, 2023
1 parent f715e75 commit 609ea19
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions BarbezDotEu.Byte/BarbezDotEu.Byte/BarbezDotEu.Byte.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<Title>BarbezDotEu.Byte</Title>
<Product>BarbezDotEu.Byte</Product>
<PackageId>BarbezDotEu.Byte</PackageId>
<Copyright2022 Hannes Barbez</Copyright>
<Version>2.1.0</Version>
<Copyright2023 Hannes Barbez</Copyright>
<Version>2.2.0</Version>
<Description>Generic logic pertaining to byte and byte arrays.</Description>
<PackageTags>byte, byte array</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
26 changes: 26 additions & 0 deletions BarbezDotEu.Byte/BarbezDotEu.Byte/CryptoHelper.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Helpers for cryptography.
/// </summary>
public static class CryptoHelper
{
/// <summary>
/// Equivalent of T-SQL's HASHBYTES('SHA2_256', &lt;toHash&gt;)".
/// </summary>
/// <param name="toHash">The string to hash.</param>
/// <returns>The result of the hash.</returns>
public static byte[] GetTsqlLikeHashBytes(string toHash)
{
byte[] hashable = Encoding.Unicode.GetBytes(toHash);
var hasher = SHA256.Create();
return hasher.ComputeHash(hashable);
}
}
}

0 comments on commit 609ea19

Please sign in to comment.