Skip to content

Commit

Permalink
Merge pull request #11 from PandaTechAM/development
Browse files Browse the repository at this point in the history
sha 3 overload
  • Loading branch information
HaikAsatryan authored Feb 12, 2024
2 parents fc35153 + ff25144 commit 1ad8bc0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 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
2 changes: 1 addition & 1 deletion src/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
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
6 changes: 3 additions & 3 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 All @@ -25,7 +25,7 @@
<PackageReference Include="BouncyCastle.NetCore" Version="2.2.1" />
<PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Pandatech.RegexBox" Version="1.1.4" />
<PackageReference Include="Pandatech.RegexBox" Version="1.2.3" />
</ItemGroup>

</Project>
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 1ad8bc0

Please sign in to comment.