From 2bbe6093f8a3a834925a8361ba8cbf60b7d3d5e0 Mon Sep 17 00:00:00 2001 From: Haik Date: Mon, 12 Feb 2024 15:46:35 +0400 Subject: [PATCH 1/2] nuget update --- src/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj | 2 +- src/Pandatech.Crypto/Pandatech.Crypto.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj b/src/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj index 840a371..14eb77f 100644 --- a/src/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj +++ b/src/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj @@ -10,7 +10,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Pandatech.Crypto/Pandatech.Crypto.csproj b/src/Pandatech.Crypto/Pandatech.Crypto.csproj index 4abb828..eb44668 100644 --- a/src/Pandatech.Crypto/Pandatech.Crypto.csproj +++ b/src/Pandatech.Crypto/Pandatech.Crypto.csproj @@ -25,7 +25,7 @@ - + From ff25144431bc723878c72628dd6f1d63c6d2d6c7 Mon Sep 17 00:00:00 2001 From: Haik Date: Mon, 12 Feb 2024 16:06:22 +0400 Subject: [PATCH 2/2] sha3 overload --- src/Pandatech.Crypto.Tests/MaskTests.cs | 2 +- src/Pandatech.Crypto.Tests/Sha3Tests.cs | 15 ++++++++++++++- src/Pandatech.Crypto/Pandatech.Crypto.csproj | 4 ++-- src/Pandatech.Crypto/Sha3.cs | 11 +++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Pandatech.Crypto.Tests/MaskTests.cs b/src/Pandatech.Crypto.Tests/MaskTests.cs index 0909d95..11a4b45 100644 --- a/src/Pandatech.Crypto.Tests/MaskTests.cs +++ b/src/Pandatech.Crypto.Tests/MaskTests.cs @@ -7,7 +7,7 @@ public class MaskTests { [Theory] - [InlineData("vazgen.Sargsyan@vazgen.com", "va***************@vazgen.com")] + [InlineData("vazgen.Sargsyan@vazgen.com", "va*************@vazgen.com")] [InlineData("test@example.com", "te**@example.com")] [InlineData("ab@c.com", "ab@c.com")] [InlineData("a@b.com", "a@b.com")] diff --git a/src/Pandatech.Crypto.Tests/Sha3Tests.cs b/src/Pandatech.Crypto.Tests/Sha3Tests.cs index f5db0f3..ef35322 100644 --- a/src/Pandatech.Crypto.Tests/Sha3Tests.cs +++ b/src/Pandatech.Crypto.Tests/Sha3Tests.cs @@ -1,4 +1,6 @@ -namespace Pandatech.Crypto.Tests; +using System.Text; + +namespace Pandatech.Crypto.Tests; public class Sha3Tests { @@ -25,6 +27,17 @@ public void Hash_VerifyHash_IsTrue() var result = Sha3.VerifyHash(data, hash); Assert.True(result); } + + [Fact] + public void Hash_VerifyHash_WithBytes_IsTrue() + { + const string data = "Hello, world!"; + var bytes = Encoding.UTF8.GetBytes(data); + var hash = Sha3.Hash(bytes); + + var result = Sha3.VerifyHash(data, hash); + Assert.True(result); + } [Fact] public void Hash_VerifyHash_IsFalse() diff --git a/src/Pandatech.Crypto/Pandatech.Crypto.csproj b/src/Pandatech.Crypto/Pandatech.Crypto.csproj index eb44668..24dec6e 100644 --- a/src/Pandatech.Crypto/Pandatech.Crypto.csproj +++ b/src/Pandatech.Crypto/Pandatech.Crypto.csproj @@ -8,12 +8,12 @@ MIT pandatech.png Readme.md - 2.2.6 + 2.2.7 Pandatech.Crypto Pandatech, library, encryption, hash, algorythms, security PandaTech.Crypto is a .NET library simplifying common cryptograhic functions. https://github.com/PandaTechAM/be-lib-pandatech-crypto - Mask class extension + Overload for sha3 diff --git a/src/Pandatech.Crypto/Sha3.cs b/src/Pandatech.Crypto/Sha3.cs index 2c4a207..884f3d5 100644 --- a/src/Pandatech.Crypto/Sha3.cs +++ b/src/Pandatech.Crypto/Sha3.cs @@ -19,6 +19,17 @@ public static byte[] Hash(string data) return result; } + public static byte[] Hash(byte[] bytes) + { + var digest = new KeccakDigest(512); + digest.BlockUpdate(bytes, 0, bytes.Length); + + var result = new byte[digest.GetDigestSize()]; + digest.DoFinal(result, 0); + + return result; + } + public static bool VerifyHash(string data, byte[] hash) { var newHash = Hash(data);