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/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.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 4abb828..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 @@ -25,7 +25,7 @@ - + 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);