Skip to content

Commit

Permalink
sha3 overload
Browse files Browse the repository at this point in the history
  • Loading branch information
Haik committed Feb 12, 2024
1 parent 2bbe609 commit ff25144
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Pandatech.Crypto.Tests/MaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class MaskTests
{
[Theory]
[InlineData("[email protected]", "va***************@vazgen.com")]
[InlineData("[email protected]", "va*************@vazgen.com")]
[InlineData("[email protected]", "te**@example.com")]
[InlineData("[email protected]", "[email protected]")]
[InlineData("[email protected]", "[email protected]")]
Expand Down
15 changes: 14 additions & 1 deletion src/Pandatech.Crypto.Tests/Sha3Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Pandatech.Crypto.Tests;
using System.Text;

namespace Pandatech.Crypto.Tests;

public class Sha3Tests
{
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/Pandatech.Crypto/Pandatech.Crypto.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<Copyright>MIT</Copyright>
<PackageIcon>pandatech.png</PackageIcon>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Version>2.2.6</Version>
<Version>2.2.7</Version>
<Title>Pandatech.Crypto</Title>
<PackageTags>Pandatech, library, encryption, hash, algorythms, security</PackageTags>
<Description>PandaTech.Crypto is a .NET library simplifying common cryptograhic functions.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-pandatech-crypto</RepositoryUrl>
<PackageReleaseNotes>Mask class extension</PackageReleaseNotes>
<PackageReleaseNotes>Overload for sha3</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions src/Pandatech.Crypto/Sha3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ff25144

Please sign in to comment.