Files
git.stella-ops.org/src/__Libraries/__Tests/StellaOps.Cryptography.Tests/DefaultCryptoHashTests.Hex.cs

32 lines
1.0 KiB
C#

using System.IO;
using System.Security.Cryptography;
using StellaOps.Cryptography;
using StellaOps.TestKit;
using Xunit;
namespace StellaOps.Cryptography.Tests;
public sealed partial class DefaultCryptoHashTests
{
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeHashHex_Sha256_MatchesBclLowerHex()
{
var hash = CryptoHashFactory.CreateDefault();
var expected = Convert.ToHexStringLower(SHA256.HashData(_sample));
var actual = hash.ComputeHashHex(_sample, HashAlgorithms.Sha256);
Assert.Equal(expected, actual);
}
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ComputeHashHex_Sha256_MatchesBclLowerHex_Async()
{
var hash = CryptoHashFactory.CreateDefault();
var expected = Convert.ToHexStringLower(SHA256.HashData(_sample));
await using var stream = new MemoryStream(_sample);
var actual = await hash.ComputeHashHexAsync(stream, HashAlgorithms.Sha256);
Assert.Equal(expected, actual);
}
}