diff --git a/PolyShim.Tests/Net50/MD5Tests.cs b/PolyShim.Tests/Net50/MD5Tests.cs new file mode 100644 index 0000000..d0d1cc0 --- /dev/null +++ b/PolyShim.Tests/Net50/MD5Tests.cs @@ -0,0 +1,75 @@ +using System; +using System.Security.Cryptography; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net50; + +public class MD5Tests +{ + [Fact] + public void HashData_Test() + { + // Arrange + var data = new byte[] { 1, 2, 3, 4, 5 }; + + // Act + var hash = MD5.HashData(data); + + // Assert + hash.Should() + .Equal([ + 0x7c, + 0xfd, + 0xd0, + 0x78, + 0x89, + 0xb3, + 0x29, + 0x5d, + 0x6a, + 0x55, + 0x09, + 0x14, + 0xab, + 0x35, + 0xe0, + 0x68, + ]); + } + + [Fact] + public void TryHashData_Test() + { + // Arrange + var data = new byte[] { 1, 2, 3, 4, 5 }; + var destination = new byte[16]; + + // Act + var result = MD5.TryHashData(data.AsSpan(), destination.AsSpan(), out var bytesWritten); + + // Assert + result.Should().BeTrue(); + bytesWritten.Should().Be(16); + destination + .Should() + .Equal([ + 0x7c, + 0xfd, + 0xd0, + 0x78, + 0x89, + 0xb3, + 0x29, + 0x5d, + 0x6a, + 0x55, + 0x09, + 0x14, + 0xab, + 0x35, + 0xe0, + 0x68, + ]); + } +} diff --git a/PolyShim.Tests/Net50/SHA1Tests.cs b/PolyShim.Tests/Net50/SHA1Tests.cs new file mode 100644 index 0000000..bd7896b --- /dev/null +++ b/PolyShim.Tests/Net50/SHA1Tests.cs @@ -0,0 +1,83 @@ +using System; +using System.Security.Cryptography; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net50; + +public class SHA1Tests +{ + [Fact] + public void HashData_Test() + { + // Arrange + var data = new byte[] { 1, 2, 3, 4, 5 }; + + // Act + var hash = SHA1.HashData(data); + + // Assert + hash.Should() + .Equal([ + 0x11, + 0x96, + 0x6a, + 0xb9, + 0xc0, + 0x99, + 0xf8, + 0xfa, + 0xbe, + 0xfa, + 0xc5, + 0x4c, + 0x08, + 0xd5, + 0xbe, + 0x2b, + 0xd8, + 0xc9, + 0x03, + 0xaf, + ]); + } + + [Fact] + public void TryHashData_Test() + { + // Arrange + var data = new byte[] { 1, 2, 3, 4, 5 }; + var destination = new byte[20]; + + // Act + var result = SHA1.TryHashData(data.AsSpan(), destination.AsSpan(), out var bytesWritten); + + // Assert + result.Should().BeTrue(); + bytesWritten.Should().Be(20); + destination + .Should() + .Equal([ + 0x11, + 0x96, + 0x6a, + 0xb9, + 0xc0, + 0x99, + 0xf8, + 0xfa, + 0xbe, + 0xfa, + 0xc5, + 0x4c, + 0x08, + 0xd5, + 0xbe, + 0x2b, + 0xd8, + 0xc9, + 0x03, + 0xaf, + ]); + } +} diff --git a/PolyShim.Tests/Net50/SHA256Tests.cs b/PolyShim.Tests/Net50/SHA256Tests.cs new file mode 100644 index 0000000..5ccf4a4 --- /dev/null +++ b/PolyShim.Tests/Net50/SHA256Tests.cs @@ -0,0 +1,107 @@ +using System; +using System.Security.Cryptography; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net50; + +public class SHA256Tests +{ + [Fact] + public void HashData_Test() + { + // Arrange + var data = new byte[] { 1, 2, 3, 4, 5 }; + + // Act + var hash = SHA256.HashData(data); + + // Assert + hash.Should() + .Equal([ + 0x74, + 0xf8, + 0x1f, + 0xe1, + 0x67, + 0xd9, + 0x9b, + 0x4c, + 0xb4, + 0x1d, + 0x6d, + 0x0c, + 0xcd, + 0xa8, + 0x22, + 0x78, + 0xca, + 0xee, + 0x9f, + 0x3e, + 0x2f, + 0x25, + 0xd5, + 0xe5, + 0xa3, + 0x93, + 0x6f, + 0xf3, + 0xdc, + 0xec, + 0x60, + 0xd0, + ]); + } + + [Fact] + public void TryHashData_Test() + { + // Arrange + var data = new byte[] { 1, 2, 3, 4, 5 }; + var destination = new byte[32]; + + // Act + var result = SHA256.TryHashData(data.AsSpan(), destination.AsSpan(), out var bytesWritten); + + // Assert + result.Should().BeTrue(); + bytesWritten.Should().Be(32); + destination + .Should() + .Equal([ + 0x74, + 0xf8, + 0x1f, + 0xe1, + 0x67, + 0xd9, + 0x9b, + 0x4c, + 0xb4, + 0x1d, + 0x6d, + 0x0c, + 0xcd, + 0xa8, + 0x22, + 0x78, + 0xca, + 0xee, + 0x9f, + 0x3e, + 0x2f, + 0x25, + 0xd5, + 0xe5, + 0xa3, + 0x93, + 0x6f, + 0xf3, + 0xdc, + 0xec, + 0x60, + 0xd0, + ]); + } +} diff --git a/PolyShim.Tests/Net50/SHA384Tests.cs b/PolyShim.Tests/Net50/SHA384Tests.cs new file mode 100644 index 0000000..1ca5105 --- /dev/null +++ b/PolyShim.Tests/Net50/SHA384Tests.cs @@ -0,0 +1,139 @@ +using System; +using System.Security.Cryptography; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net50; + +public class SHA384Tests +{ + [Fact] + public void HashData_Test() + { + // Arrange + var data = new byte[] { 1, 2, 3, 4, 5 }; + + // Act + var hash = SHA384.HashData(data); + + // Assert + hash.Should() + .Equal([ + 0xd8, + 0x88, + 0x75, + 0xdb, + 0x0f, + 0x77, + 0xaa, + 0xd8, + 0xf3, + 0xd9, + 0x94, + 0xfe, + 0x68, + 0xcd, + 0x1c, + 0xc7, + 0xec, + 0x3a, + 0x4f, + 0xf1, + 0x43, + 0x78, + 0xb7, + 0xfe, + 0xb9, + 0x91, + 0xe5, + 0x47, + 0x84, + 0x85, + 0x01, + 0x92, + 0x14, + 0x58, + 0x54, + 0xc3, + 0x6e, + 0x5a, + 0x40, + 0xa0, + 0xc2, + 0xe8, + 0x0d, + 0xa2, + 0x00, + 0x2d, + 0x7c, + 0xc8, + ]); + } + + [Fact] + public void TryHashData_Test() + { + // Arrange + var data = new byte[] { 1, 2, 3, 4, 5 }; + var destination = new byte[48]; + + // Act + var result = SHA384.TryHashData(data.AsSpan(), destination.AsSpan(), out var bytesWritten); + + // Assert + result.Should().BeTrue(); + bytesWritten.Should().Be(48); + destination + .Should() + .Equal([ + 0xd8, + 0x88, + 0x75, + 0xdb, + 0x0f, + 0x77, + 0xaa, + 0xd8, + 0xf3, + 0xd9, + 0x94, + 0xfe, + 0x68, + 0xcd, + 0x1c, + 0xc7, + 0xec, + 0x3a, + 0x4f, + 0xf1, + 0x43, + 0x78, + 0xb7, + 0xfe, + 0xb9, + 0x91, + 0xe5, + 0x47, + 0x84, + 0x85, + 0x01, + 0x92, + 0x14, + 0x58, + 0x54, + 0xc3, + 0x6e, + 0x5a, + 0x40, + 0xa0, + 0xc2, + 0xe8, + 0x0d, + 0xa2, + 0x00, + 0x2d, + 0x7c, + 0xc8, + ]); + } +} diff --git a/PolyShim.Tests/Net50/SHA512Tests.cs b/PolyShim.Tests/Net50/SHA512Tests.cs new file mode 100644 index 0000000..8317641 --- /dev/null +++ b/PolyShim.Tests/Net50/SHA512Tests.cs @@ -0,0 +1,171 @@ +using System; +using System.Security.Cryptography; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net50; + +public class SHA512Tests +{ + [Fact] + public void HashData_Test() + { + // Arrange + var data = new byte[] { 1, 2, 3, 4, 5 }; + + // Act + var hash = SHA512.HashData(data); + + // Assert + hash.Should() + .Equal([ + 0x50, + 0x54, + 0x0b, + 0xc4, + 0xae, + 0x31, + 0x87, + 0x5f, + 0xce, + 0xb3, + 0x82, + 0x94, + 0x34, + 0xc5, + 0x5e, + 0x3c, + 0x2b, + 0x66, + 0xdd, + 0xd7, + 0x22, + 0x7a, + 0x88, + 0x3a, + 0x3b, + 0x4c, + 0xc8, + 0xf6, + 0xcd, + 0xa9, + 0x65, + 0xad, + 0x17, + 0x12, + 0xb3, + 0xee, + 0x00, + 0x08, + 0xf9, + 0xce, + 0xe0, + 0x8d, + 0xa9, + 0x3f, + 0x52, + 0x34, + 0xc1, + 0xa7, + 0xbf, + 0x0e, + 0x25, + 0x70, + 0xef, + 0x56, + 0xd6, + 0x52, + 0x80, + 0xff, + 0xea, + 0x69, + 0x1b, + 0x95, + 0x3e, + 0xfe, + ]); + } + + [Fact] + public void TryHashData_Test() + { + // Arrange + var data = new byte[] { 1, 2, 3, 4, 5 }; + var destination = new byte[64]; + + // Act + var result = SHA512.TryHashData(data.AsSpan(), destination.AsSpan(), out var bytesWritten); + + // Assert + result.Should().BeTrue(); + bytesWritten.Should().Be(64); + destination + .Should() + .Equal([ + 0x50, + 0x54, + 0x0b, + 0xc4, + 0xae, + 0x31, + 0x87, + 0x5f, + 0xce, + 0xb3, + 0x82, + 0x94, + 0x34, + 0xc5, + 0x5e, + 0x3c, + 0x2b, + 0x66, + 0xdd, + 0xd7, + 0x22, + 0x7a, + 0x88, + 0x3a, + 0x3b, + 0x4c, + 0xc8, + 0xf6, + 0xcd, + 0xa9, + 0x65, + 0xad, + 0x17, + 0x12, + 0xb3, + 0xee, + 0x00, + 0x08, + 0xf9, + 0xce, + 0xe0, + 0x8d, + 0xa9, + 0x3f, + 0x52, + 0x34, + 0xc1, + 0xa7, + 0xbf, + 0x0e, + 0x25, + 0x70, + 0xef, + 0x56, + 0xd6, + 0x52, + 0x80, + 0xff, + 0xea, + 0x69, + 0x1b, + 0x95, + 0x3e, + 0xfe, + ]); + } +} diff --git a/PolyShim.Tests/Net70/MD5Tests.cs b/PolyShim.Tests/Net70/MD5Tests.cs new file mode 100644 index 0000000..166350e --- /dev/null +++ b/PolyShim.Tests/Net70/MD5Tests.cs @@ -0,0 +1,44 @@ +using System.IO; +using System.Security.Cryptography; +using System.Threading.Tasks; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net70; + +public class MD5Tests +{ + [Fact] + public async Task HashDataAsync_Test() + { + // Arrange + using var stream = new MemoryStream([1, 2, 3, 4, 5]); + var destination = new byte[16]; + + // Act + var bytesWritten = await MD5.HashDataAsync(stream, destination); + + // Assert + bytesWritten.Should().Be(16); + destination + .Should() + .Equal([ + 0x7c, + 0xfd, + 0xd0, + 0x78, + 0x89, + 0xb3, + 0x29, + 0x5d, + 0x6a, + 0x55, + 0x09, + 0x14, + 0xab, + 0x35, + 0xe0, + 0x68, + ]); + } +} diff --git a/PolyShim.Tests/Net70/SHA1Tests.cs b/PolyShim.Tests/Net70/SHA1Tests.cs new file mode 100644 index 0000000..6529ccc --- /dev/null +++ b/PolyShim.Tests/Net70/SHA1Tests.cs @@ -0,0 +1,48 @@ +using System.IO; +using System.Security.Cryptography; +using System.Threading.Tasks; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net70; + +public class SHA1Tests +{ + [Fact] + public async Task HashDataAsync_Test() + { + // Arrange + using var stream = new MemoryStream([1, 2, 3, 4, 5]); + var destination = new byte[20]; + + // Act + var bytesWritten = await SHA1.HashDataAsync(stream, destination); + + // Assert + bytesWritten.Should().Be(20); + destination + .Should() + .Equal([ + 0x11, + 0x96, + 0x6a, + 0xb9, + 0xc0, + 0x99, + 0xf8, + 0xfa, + 0xbe, + 0xfa, + 0xc5, + 0x4c, + 0x08, + 0xd5, + 0xbe, + 0x2b, + 0xd8, + 0xc9, + 0x03, + 0xaf, + ]); + } +} diff --git a/PolyShim.Tests/Net70/SHA256Tests.cs b/PolyShim.Tests/Net70/SHA256Tests.cs new file mode 100644 index 0000000..c31be45 --- /dev/null +++ b/PolyShim.Tests/Net70/SHA256Tests.cs @@ -0,0 +1,60 @@ +using System.IO; +using System.Security.Cryptography; +using System.Threading.Tasks; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net70; + +public class SHA256Tests +{ + [Fact] + public async Task HashDataAsync_Test() + { + // Arrange + using var stream = new MemoryStream([1, 2, 3, 4, 5]); + var destination = new byte[32]; + + // Act + var bytesWritten = await SHA256.HashDataAsync(stream, destination); + + // Assert + bytesWritten.Should().Be(32); + destination + .Should() + .Equal([ + 0x74, + 0xf8, + 0x1f, + 0xe1, + 0x67, + 0xd9, + 0x9b, + 0x4c, + 0xb4, + 0x1d, + 0x6d, + 0x0c, + 0xcd, + 0xa8, + 0x22, + 0x78, + 0xca, + 0xee, + 0x9f, + 0x3e, + 0x2f, + 0x25, + 0xd5, + 0xe5, + 0xa3, + 0x93, + 0x6f, + 0xf3, + 0xdc, + 0xec, + 0x60, + 0xd0, + ]); + } +} diff --git a/PolyShim.Tests/Net70/SHA384Tests.cs b/PolyShim.Tests/Net70/SHA384Tests.cs new file mode 100644 index 0000000..f44c2df --- /dev/null +++ b/PolyShim.Tests/Net70/SHA384Tests.cs @@ -0,0 +1,76 @@ +using System.IO; +using System.Security.Cryptography; +using System.Threading.Tasks; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net70; + +public class SHA384Tests +{ + [Fact] + public async Task HashDataAsync_Test() + { + // Arrange + using var stream = new MemoryStream([1, 2, 3, 4, 5]); + var destination = new byte[48]; + + // Act + var bytesWritten = await SHA384.HashDataAsync(stream, destination); + + // Assert + bytesWritten.Should().Be(48); + destination + .Should() + .Equal([ + 0xd8, + 0x88, + 0x75, + 0xdb, + 0x0f, + 0x77, + 0xaa, + 0xd8, + 0xf3, + 0xd9, + 0x94, + 0xfe, + 0x68, + 0xcd, + 0x1c, + 0xc7, + 0xec, + 0x3a, + 0x4f, + 0xf1, + 0x43, + 0x78, + 0xb7, + 0xfe, + 0xb9, + 0x91, + 0xe5, + 0x47, + 0x84, + 0x85, + 0x01, + 0x92, + 0x14, + 0x58, + 0x54, + 0xc3, + 0x6e, + 0x5a, + 0x40, + 0xa0, + 0xc2, + 0xe8, + 0x0d, + 0xa2, + 0x00, + 0x2d, + 0x7c, + 0xc8, + ]); + } +} diff --git a/PolyShim.Tests/Net70/SHA512Tests.cs b/PolyShim.Tests/Net70/SHA512Tests.cs new file mode 100644 index 0000000..3913b49 --- /dev/null +++ b/PolyShim.Tests/Net70/SHA512Tests.cs @@ -0,0 +1,92 @@ +using System.IO; +using System.Security.Cryptography; +using System.Threading.Tasks; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net70; + +public class SHA512Tests +{ + [Fact] + public async Task HashDataAsync_Test() + { + // Arrange + using var stream = new MemoryStream([1, 2, 3, 4, 5]); + var destination = new byte[64]; + + // Act + var bytesWritten = await SHA512.HashDataAsync(stream, destination); + + // Assert + bytesWritten.Should().Be(64); + destination + .Should() + .Equal([ + 0x50, + 0x54, + 0x0b, + 0xc4, + 0xae, + 0x31, + 0x87, + 0x5f, + 0xce, + 0xb3, + 0x82, + 0x94, + 0x34, + 0xc5, + 0x5e, + 0x3c, + 0x2b, + 0x66, + 0xdd, + 0xd7, + 0x22, + 0x7a, + 0x88, + 0x3a, + 0x3b, + 0x4c, + 0xc8, + 0xf6, + 0xcd, + 0xa9, + 0x65, + 0xad, + 0x17, + 0x12, + 0xb3, + 0xee, + 0x00, + 0x08, + 0xf9, + 0xce, + 0xe0, + 0x8d, + 0xa9, + 0x3f, + 0x52, + 0x34, + 0xc1, + 0xa7, + 0xbf, + 0x0e, + 0x25, + 0x70, + 0xef, + 0x56, + 0xd6, + 0x52, + 0x80, + 0xff, + 0xea, + 0x69, + 0x1b, + 0x95, + 0x3e, + 0xfe, + ]); + } +} diff --git a/PolyShim/Net50/HashAlgorithm.cs b/PolyShim/Net50/HashAlgorithm.cs new file mode 100644 index 0000000..2827aee --- /dev/null +++ b/PolyShim/Net50/HashAlgorithm.cs @@ -0,0 +1,31 @@ +#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// HashAlgorithm is not available on .NET Standard < 1.3 +#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER +#nullable enable +#pragma warning disable CS0436 + +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Security.Cryptography; +using System.Threading; +using System.Threading.Tasks; + +#if !POLYSHIM_INCLUDE_COVERAGE +[ExcludeFromCodeCoverage] +#endif +internal static class MemberPolyfills_Net50_HashAlgorithm +{ + extension(HashAlgorithm hashAlgorithm) + { + // Task infrastructure is required for async method support +#if FEATURE_TASK + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.hashalgorithm.computehashasync + public async Task ComputeHashAsync( + Stream inputStream, + CancellationToken cancellationToken = default + ) => await Task.Run(() => hashAlgorithm.ComputeHash(inputStream), cancellationToken).ConfigureAwait(false); +#endif + } +} +#endif +#endif diff --git a/PolyShim/Net50/MD5.cs b/PolyShim/Net50/MD5.cs new file mode 100644 index 0000000..1c76c34 --- /dev/null +++ b/PolyShim/Net50/MD5.cs @@ -0,0 +1,60 @@ +#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// MD5 is not available on .NET Standard < 1.3 +#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER +#nullable enable +#pragma warning disable CS0436 + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Security.Cryptography; + +#if !POLYSHIM_INCLUDE_COVERAGE +[ExcludeFromCodeCoverage] +#endif +internal static class MemberPolyfills_Net50_MD5 +{ + extension(MD5) + { + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdata#system-security-cryptography-md5-hashdata(system-byte()) + public static byte[] HashData(byte[] source) + { + using var md5 = MD5.Create(); + return md5.ComputeHash(source); + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdata#system-security-cryptography-md5-hashdata(system-readonlyspan((system-byte))) + public static byte[] HashData(ReadOnlySpan source) => MD5.HashData(source.ToArray()); + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdata#system-security-cryptography-md5-hashdata(system-readonlyspan((system-byte))-system-span((system-byte))) + public static int HashData(ReadOnlySpan source, Span destination) + { + var hash = MD5.HashData(source); + if (destination.Length < hash.Length) + throw new ArgumentException("Destination is too short.", nameof(destination)); + + hash.AsSpan().CopyTo(destination); + return hash.Length; + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.tryhashdata + public static bool TryHashData( + ReadOnlySpan source, + Span destination, + out int bytesWritten + ) + { + try + { + bytesWritten = MD5.HashData(source, destination); + return true; + } + catch (ArgumentException) + { + bytesWritten = 0; + return false; + } + } + } +} +#endif +#endif diff --git a/PolyShim/Net50/SHA1.cs b/PolyShim/Net50/SHA1.cs new file mode 100644 index 0000000..d9ade07 --- /dev/null +++ b/PolyShim/Net50/SHA1.cs @@ -0,0 +1,60 @@ +#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// SHA1 is not available on .NET Standard < 1.3 +#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER +#nullable enable +#pragma warning disable CS0436 + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Security.Cryptography; + +#if !POLYSHIM_INCLUDE_COVERAGE +[ExcludeFromCodeCoverage] +#endif +internal static class MemberPolyfills_Net50_SHA1 +{ + extension(SHA1) + { + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdata#system-security-cryptography-sha1-hashdata(system-byte()) + public static byte[] HashData(byte[] source) + { + using var sha = SHA1.Create(); + return sha.ComputeHash(source); + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdata#system-security-cryptography-sha1-hashdata(system-readonlyspan((system-byte))) + public static byte[] HashData(ReadOnlySpan source) => SHA1.HashData(source.ToArray()); + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdata#system-security-cryptography-sha1-hashdata(system-readonlyspan((system-byte))-system-span((system-byte))) + public static int HashData(ReadOnlySpan source, Span destination) + { + var hash = SHA1.HashData(source); + if (destination.Length < hash.Length) + throw new ArgumentException("Destination is too short.", nameof(destination)); + + hash.AsSpan().CopyTo(destination); + return hash.Length; + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.tryhashdata + public static bool TryHashData( + ReadOnlySpan source, + Span destination, + out int bytesWritten + ) + { + try + { + bytesWritten = SHA1.HashData(source, destination); + return true; + } + catch (ArgumentException) + { + bytesWritten = 0; + return false; + } + } + } +} +#endif +#endif diff --git a/PolyShim/Net50/SHA256.cs b/PolyShim/Net50/SHA256.cs new file mode 100644 index 0000000..269aec5 --- /dev/null +++ b/PolyShim/Net50/SHA256.cs @@ -0,0 +1,61 @@ +#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// SHA256 is not available on .NET Standard < 1.3 +#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER +#nullable enable +#pragma warning disable CS0436 + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Security.Cryptography; + +#if !POLYSHIM_INCLUDE_COVERAGE +[ExcludeFromCodeCoverage] +#endif +internal static class MemberPolyfills_Net50_SHA256 +{ + extension(SHA256) + { + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdata#system-security-cryptography-sha256-hashdata(system-byte()) + public static byte[] HashData(byte[] source) + { + using var sha = SHA256.Create(); + return sha.ComputeHash(source); + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdata#system-security-cryptography-sha256-hashdata(system-readonlyspan((system-byte))) + public static byte[] HashData(ReadOnlySpan source) => + SHA256.HashData(source.ToArray()); + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdata#system-security-cryptography-sha256-hashdata(system-readonlyspan((system-byte))-system-span((system-byte))) + public static int HashData(ReadOnlySpan source, Span destination) + { + var hash = SHA256.HashData(source); + if (destination.Length < hash.Length) + throw new ArgumentException("Destination is too short.", nameof(destination)); + + hash.AsSpan().CopyTo(destination); + return hash.Length; + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.tryhashdata + public static bool TryHashData( + ReadOnlySpan source, + Span destination, + out int bytesWritten + ) + { + try + { + bytesWritten = SHA256.HashData(source, destination); + return true; + } + catch (ArgumentException) + { + bytesWritten = 0; + return false; + } + } + } +} +#endif +#endif diff --git a/PolyShim/Net50/SHA384.cs b/PolyShim/Net50/SHA384.cs new file mode 100644 index 0000000..8824167 --- /dev/null +++ b/PolyShim/Net50/SHA384.cs @@ -0,0 +1,61 @@ +#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// SHA384 is not available on .NET Standard < 1.3 +#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER +#nullable enable +#pragma warning disable CS0436 + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Security.Cryptography; + +#if !POLYSHIM_INCLUDE_COVERAGE +[ExcludeFromCodeCoverage] +#endif +internal static class MemberPolyfills_Net50_SHA384 +{ + extension(SHA384) + { + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdata#system-security-cryptography-sha384-hashdata(system-byte()) + public static byte[] HashData(byte[] source) + { + using var sha = SHA384.Create(); + return sha.ComputeHash(source); + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdata#system-security-cryptography-sha384-hashdata(system-readonlyspan((system-byte))) + public static byte[] HashData(ReadOnlySpan source) => + SHA384.HashData(source.ToArray()); + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdata#system-security-cryptography-sha384-hashdata(system-readonlyspan((system-byte))-system-span((system-byte))) + public static int HashData(ReadOnlySpan source, Span destination) + { + var hash = SHA384.HashData(source); + if (destination.Length < hash.Length) + throw new ArgumentException("Destination is too short.", nameof(destination)); + + hash.AsSpan().CopyTo(destination); + return hash.Length; + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.tryhashdata + public static bool TryHashData( + ReadOnlySpan source, + Span destination, + out int bytesWritten + ) + { + try + { + bytesWritten = SHA384.HashData(source, destination); + return true; + } + catch (ArgumentException) + { + bytesWritten = 0; + return false; + } + } + } +} +#endif +#endif diff --git a/PolyShim/Net50/SHA512.cs b/PolyShim/Net50/SHA512.cs new file mode 100644 index 0000000..99fd8cb --- /dev/null +++ b/PolyShim/Net50/SHA512.cs @@ -0,0 +1,61 @@ +#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// SHA512 is not available on .NET Standard < 1.3 +#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER +#nullable enable +#pragma warning disable CS0436 + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Security.Cryptography; + +#if !POLYSHIM_INCLUDE_COVERAGE +[ExcludeFromCodeCoverage] +#endif +internal static class MemberPolyfills_Net50_SHA512 +{ + extension(SHA512) + { + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdata#system-security-cryptography-sha512-hashdata(system-byte()) + public static byte[] HashData(byte[] source) + { + using var sha = SHA512.Create(); + return sha.ComputeHash(source); + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdata#system-security-cryptography-sha512-hashdata(system-readonlyspan((system-byte))) + public static byte[] HashData(ReadOnlySpan source) => + SHA512.HashData(source.ToArray()); + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdata#system-security-cryptography-sha512-hashdata(system-readonlyspan((system-byte))-system-span((system-byte))) + public static int HashData(ReadOnlySpan source, Span destination) + { + var hash = SHA512.HashData(source); + if (destination.Length < hash.Length) + throw new ArgumentException("Destination is too short.", nameof(destination)); + + hash.AsSpan().CopyTo(destination); + return hash.Length; + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.tryhashdata + public static bool TryHashData( + ReadOnlySpan source, + Span destination, + out int bytesWritten + ) + { + try + { + bytesWritten = SHA512.HashData(source, destination); + return true; + } + catch (ArgumentException) + { + bytesWritten = 0; + return false; + } + } + } +} +#endif +#endif diff --git a/PolyShim/Net70/MD5.cs b/PolyShim/Net70/MD5.cs new file mode 100644 index 0000000..719a3b0 --- /dev/null +++ b/PolyShim/Net70/MD5.cs @@ -0,0 +1,61 @@ +#if (NETCOREAPP && !NET7_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// MD5 is not available on .NET Standard < 1.3 +#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER +#nullable enable +#pragma warning disable CS0436 + +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Security.Cryptography; +using System.Threading; +using System.Threading.Tasks; + +#if !POLYSHIM_INCLUDE_COVERAGE +[ExcludeFromCodeCoverage] +#endif +internal static class MemberPolyfills_Net70_MD5 +{ + extension(MD5) + { + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdata#system-security-cryptography-md5-hashdata(system-io-stream) + public static byte[] HashData(Stream source) + { + using var md5 = MD5.Create(); + return md5.ComputeHash(source); + } + + // Task infrastructure is required for async method support +#if FEATURE_TASK + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdataasync#system-security-cryptography-md5-hashdataasync(system-io-stream-system-threading-cancellationtoken) + public static async ValueTask HashDataAsync( + Stream source, + CancellationToken cancellationToken = default + ) + { + using var md5 = MD5.Create(); + return await md5.ComputeHashAsync(source, cancellationToken).ConfigureAwait(false); + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdataasync#system-security-cryptography-md5-hashdataasync(system-io-stream-system-memory((system-byte))-system-threading-cancellationtoken) + public static async ValueTask HashDataAsync( + Stream source, + Memory destination, + CancellationToken cancellationToken = default + ) + { + var hash = await MD5 + .HashDataAsync(source, cancellationToken) + .ConfigureAwait(false); + + if (destination.Length < hash.Length) + throw new ArgumentException("Destination is too short.", nameof(destination)); + + hash.AsMemory().CopyTo(destination); + return hash.Length; + } +#endif + } +} +#endif +#endif diff --git a/PolyShim/Net70/SHA1.cs b/PolyShim/Net70/SHA1.cs new file mode 100644 index 0000000..3416066 --- /dev/null +++ b/PolyShim/Net70/SHA1.cs @@ -0,0 +1,61 @@ +#if (NETCOREAPP && !NET7_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// SHA1 is not available on .NET Standard < 1.3 +#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER +#nullable enable +#pragma warning disable CS0436 + +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Security.Cryptography; +using System.Threading; +using System.Threading.Tasks; + +#if !POLYSHIM_INCLUDE_COVERAGE +[ExcludeFromCodeCoverage] +#endif +internal static class MemberPolyfills_Net70_SHA1 +{ + extension(SHA1) + { + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdata#system-security-cryptography-sha1-hashdata(system-io-stream) + public static byte[] HashData(Stream source) + { + using var sha = SHA1.Create(); + return sha.ComputeHash(source); + } + + // Task infrastructure is required for async method support +#if FEATURE_TASK + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdataasync#system-security-cryptography-sha1-hashdataasync(system-io-stream-system-threading-cancellationtoken) + public static async ValueTask HashDataAsync( + Stream source, + CancellationToken cancellationToken = default + ) + { + using var sha = SHA1.Create(); + return await sha.ComputeHashAsync(source, cancellationToken).ConfigureAwait(false); + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdataasync#system-security-cryptography-sha1-hashdataasync(system-io-stream-system-memory((system-byte))-system-threading-cancellationtoken) + public static async ValueTask HashDataAsync( + Stream source, + Memory destination, + CancellationToken cancellationToken = default + ) + { + var hash = await SHA1 + .HashDataAsync(source, cancellationToken) + .ConfigureAwait(false); + + if (destination.Length < hash.Length) + throw new ArgumentException("Destination is too short.", nameof(destination)); + + hash.AsMemory().CopyTo(destination); + return hash.Length; + } +#endif + } +} +#endif +#endif diff --git a/PolyShim/Net70/SHA256.cs b/PolyShim/Net70/SHA256.cs new file mode 100644 index 0000000..2010025 --- /dev/null +++ b/PolyShim/Net70/SHA256.cs @@ -0,0 +1,61 @@ +#if (NETCOREAPP && !NET7_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// SHA256 is not available on .NET Standard < 1.3 +#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER +#nullable enable +#pragma warning disable CS0436 + +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Security.Cryptography; +using System.Threading; +using System.Threading.Tasks; + +#if !POLYSHIM_INCLUDE_COVERAGE +[ExcludeFromCodeCoverage] +#endif +internal static class MemberPolyfills_Net70_SHA256 +{ + extension(SHA256) + { + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdata#system-security-cryptography-sha256-hashdata(system-io-stream) + public static byte[] HashData(Stream source) + { + using var sha = SHA256.Create(); + return sha.ComputeHash(source); + } + + // Task infrastructure is required for async method support +#if FEATURE_TASK + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdataasync#system-security-cryptography-sha256-hashdataasync(system-io-stream-system-threading-cancellationtoken) + public static async ValueTask HashDataAsync( + Stream source, + CancellationToken cancellationToken = default + ) + { + using var sha = SHA256.Create(); + return await sha.ComputeHashAsync(source, cancellationToken).ConfigureAwait(false); + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdataasync#system-security-cryptography-sha256-hashdataasync(system-io-stream-system-memory((system-byte))-system-threading-cancellationtoken) + public static async ValueTask HashDataAsync( + Stream source, + Memory destination, + CancellationToken cancellationToken = default + ) + { + var hash = await SHA256 + .HashDataAsync(source, cancellationToken) + .ConfigureAwait(false); + + if (destination.Length < hash.Length) + throw new ArgumentException("Destination is too short.", nameof(destination)); + + hash.AsMemory().CopyTo(destination); + return hash.Length; + } +#endif + } +} +#endif +#endif diff --git a/PolyShim/Net70/SHA384.cs b/PolyShim/Net70/SHA384.cs new file mode 100644 index 0000000..f53cc71 --- /dev/null +++ b/PolyShim/Net70/SHA384.cs @@ -0,0 +1,61 @@ +#if (NETCOREAPP && !NET7_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// SHA384 is not available on .NET Standard < 1.3 +#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER +#nullable enable +#pragma warning disable CS0436 + +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Security.Cryptography; +using System.Threading; +using System.Threading.Tasks; + +#if !POLYSHIM_INCLUDE_COVERAGE +[ExcludeFromCodeCoverage] +#endif +internal static class MemberPolyfills_Net70_SHA384 +{ + extension(SHA384) + { + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdata#system-security-cryptography-sha384-hashdata(system-io-stream) + public static byte[] HashData(Stream source) + { + using var sha = SHA384.Create(); + return sha.ComputeHash(source); + } + + // Task infrastructure is required for async method support +#if FEATURE_TASK + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdataasync#system-security-cryptography-sha384-hashdataasync(system-io-stream-system-threading-cancellationtoken) + public static async ValueTask HashDataAsync( + Stream source, + CancellationToken cancellationToken = default + ) + { + using var sha = SHA384.Create(); + return await sha.ComputeHashAsync(source, cancellationToken).ConfigureAwait(false); + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdataasync#system-security-cryptography-sha384-hashdataasync(system-io-stream-system-memory((system-byte))-system-threading-cancellationtoken) + public static async ValueTask HashDataAsync( + Stream source, + Memory destination, + CancellationToken cancellationToken = default + ) + { + var hash = await SHA384 + .HashDataAsync(source, cancellationToken) + .ConfigureAwait(false); + + if (destination.Length < hash.Length) + throw new ArgumentException("Destination is too short.", nameof(destination)); + + hash.AsMemory().CopyTo(destination); + return hash.Length; + } +#endif + } +} +#endif +#endif diff --git a/PolyShim/Net70/SHA512.cs b/PolyShim/Net70/SHA512.cs new file mode 100644 index 0000000..bb2c238 --- /dev/null +++ b/PolyShim/Net70/SHA512.cs @@ -0,0 +1,61 @@ +#if (NETCOREAPP && !NET7_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +// SHA512 is not available on .NET Standard < 1.3 +#if !NETSTANDARD || NETSTANDARD1_3_OR_GREATER +#nullable enable +#pragma warning disable CS0436 + +using System; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Security.Cryptography; +using System.Threading; +using System.Threading.Tasks; + +#if !POLYSHIM_INCLUDE_COVERAGE +[ExcludeFromCodeCoverage] +#endif +internal static class MemberPolyfills_Net70_SHA512 +{ + extension(SHA512) + { + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdata#system-security-cryptography-sha512-hashdata(system-io-stream) + public static byte[] HashData(Stream source) + { + using var sha = SHA512.Create(); + return sha.ComputeHash(source); + } + + // Task infrastructure is required for async method support +#if FEATURE_TASK + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdataasync#system-security-cryptography-sha512-hashdataasync(system-io-stream-system-threading-cancellationtoken) + public static async ValueTask HashDataAsync( + Stream source, + CancellationToken cancellationToken = default + ) + { + using var sha = SHA512.Create(); + return await sha.ComputeHashAsync(source, cancellationToken).ConfigureAwait(false); + } + + // https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdataasync#system-security-cryptography-sha512-hashdataasync(system-io-stream-system-memory((system-byte))-system-threading-cancellationtoken) + public static async ValueTask HashDataAsync( + Stream source, + Memory destination, + CancellationToken cancellationToken = default + ) + { + var hash = await SHA512 + .HashDataAsync(source, cancellationToken) + .ConfigureAwait(false); + + if (destination.Length < hash.Length) + throw new ArgumentException("Destination is too short.", nameof(destination)); + + hash.AsMemory().CopyTo(destination); + return hash.Length; + } +#endif + } +} +#endif +#endif diff --git a/Signatures.md b/Signatures.md index 8a6559d..a9e10db 100644 --- a/Signatures.md +++ b/Signatures.md @@ -1,8 +1,8 @@ # Signatures -- **Total:** 495 +- **Total:** 531 - **Types:** 113 -- **Members:** 382 +- **Members:** 418 ___ @@ -167,6 +167,8 @@ ___ - `Guid` - [`static bool TryParse(string?, out Guid)`](https://learn.microsoft.com/dotnet/api/system.guid.tryparse) .NET Core 1.0 - [`static Guid Parse(string)`](https://learn.microsoft.com/dotnet/api/system.guid.parse) .NET Core 1.0 +- `HashAlgorithm` + - [`Task ComputeHashAsync(Stream, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.hashalgorithm.computehashasync) .NET 5.0 - `HashCode` - [**[class]**](https://learn.microsoft.com/dotnet/api/system.hashcode) .NET Core 2.1 - `HashSet` @@ -309,6 +311,14 @@ ___ - [**[class]**](https://learn.microsoft.com/dotnet/api/system.diagnostics.codeanalysis.maybenullattribute) .NET Core 3.0 - `MaybeNullWhenAttribute` - [**[class]**](https://learn.microsoft.com/dotnet/api/system.diagnostics.codeanalysis.maybenullwhenattribute) .NET Core 3.0 +- `MD5` + - [`static bool TryHashData(ReadOnlySpan, Span, out int)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.tryhashdata) .NET 5.0 + - [`static byte[] HashData(byte[])`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdata#system-security-cryptography-md5-hashdata(system-byte())) .NET 5.0 + - [`static byte[] HashData(ReadOnlySpan)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdata#system-security-cryptography-md5-hashdata(system-readonlyspan((system-byte)))) .NET 5.0 + - [`static byte[] HashData(Stream)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdata#system-security-cryptography-md5-hashdata(system-io-stream)) .NET 7.0 + - [`static int HashData(ReadOnlySpan, Span)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdata#system-security-cryptography-md5-hashdata(system-readonlyspan((system-byte))-system-span((system-byte)))) .NET 5.0 + - [`static ValueTask HashDataAsync(Stream, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdataasync#system-security-cryptography-md5-hashdataasync(system-io-stream-system-threading-cancellationtoken)) .NET 7.0 + - [`static ValueTask HashDataAsync(Stream, Memory, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.md5.hashdataasync#system-security-cryptography-md5-hashdataasync(system-io-stream-system-memory((system-byte))-system-threading-cancellationtoken)) .NET 7.0 - `MemberInfo` - [`T? GetCustomAttribute() where T : Attribute`](https://learn.microsoft.com/dotnet/api/system.reflection.customattributeextensions.getcustomattribute#system-reflection-customattributeextensions-getcustomattribute-1(system-reflection-memberinfo)) .NET Core 1.0 - [`T? GetCustomAttribute(bool) where T : Attribute`](https://learn.microsoft.com/dotnet/api/system.reflection.customattributeextensions.getcustomattribute#system-reflection-customattributeextensions-getcustomattribute-1(system-reflection-memberinfo-system-boolean)) .NET Core 1.0 @@ -454,6 +464,38 @@ ___ - [`Task WaitAsync(TimeSpan, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.threading.semaphoreslim.waitasync#system-threading-semaphoreslim-waitasync(system-timespan-system-threading-cancellationtoken)) .NET Core 1.0 - `SetsRequiredMembersAttribute` - [**[class]**](https://learn.microsoft.com/dotnet/api/system.diagnostics.codeanalysis.setsrequiredmembersattribute) .NET 7.0 +- `SHA1` + - [`static bool TryHashData(ReadOnlySpan, Span, out int)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.tryhashdata) .NET 5.0 + - [`static byte[] HashData(byte[])`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdata#system-security-cryptography-sha1-hashdata(system-byte())) .NET 5.0 + - [`static byte[] HashData(ReadOnlySpan)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdata#system-security-cryptography-sha1-hashdata(system-readonlyspan((system-byte)))) .NET 5.0 + - [`static byte[] HashData(Stream)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdata#system-security-cryptography-sha1-hashdata(system-io-stream)) .NET 7.0 + - [`static int HashData(ReadOnlySpan, Span)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdata#system-security-cryptography-sha1-hashdata(system-readonlyspan((system-byte))-system-span((system-byte)))) .NET 5.0 + - [`static ValueTask HashDataAsync(Stream, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdataasync#system-security-cryptography-sha1-hashdataasync(system-io-stream-system-threading-cancellationtoken)) .NET 7.0 + - [`static ValueTask HashDataAsync(Stream, Memory, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha1.hashdataasync#system-security-cryptography-sha1-hashdataasync(system-io-stream-system-memory((system-byte))-system-threading-cancellationtoken)) .NET 7.0 +- `SHA256` + - [`static bool TryHashData(ReadOnlySpan, Span, out int)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.tryhashdata) .NET 5.0 + - [`static byte[] HashData(byte[])`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdata#system-security-cryptography-sha256-hashdata(system-byte())) .NET 5.0 + - [`static byte[] HashData(ReadOnlySpan)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdata#system-security-cryptography-sha256-hashdata(system-readonlyspan((system-byte)))) .NET 5.0 + - [`static byte[] HashData(Stream)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdata#system-security-cryptography-sha256-hashdata(system-io-stream)) .NET 7.0 + - [`static int HashData(ReadOnlySpan, Span)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdata#system-security-cryptography-sha256-hashdata(system-readonlyspan((system-byte))-system-span((system-byte)))) .NET 5.0 + - [`static ValueTask HashDataAsync(Stream, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdataasync#system-security-cryptography-sha256-hashdataasync(system-io-stream-system-threading-cancellationtoken)) .NET 7.0 + - [`static ValueTask HashDataAsync(Stream, Memory, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha256.hashdataasync#system-security-cryptography-sha256-hashdataasync(system-io-stream-system-memory((system-byte))-system-threading-cancellationtoken)) .NET 7.0 +- `SHA384` + - [`static bool TryHashData(ReadOnlySpan, Span, out int)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.tryhashdata) .NET 5.0 + - [`static byte[] HashData(byte[])`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdata#system-security-cryptography-sha384-hashdata(system-byte())) .NET 5.0 + - [`static byte[] HashData(ReadOnlySpan)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdata#system-security-cryptography-sha384-hashdata(system-readonlyspan((system-byte)))) .NET 5.0 + - [`static byte[] HashData(Stream)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdata#system-security-cryptography-sha384-hashdata(system-io-stream)) .NET 7.0 + - [`static int HashData(ReadOnlySpan, Span)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdata#system-security-cryptography-sha384-hashdata(system-readonlyspan((system-byte))-system-span((system-byte)))) .NET 5.0 + - [`static ValueTask HashDataAsync(Stream, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdataasync#system-security-cryptography-sha384-hashdataasync(system-io-stream-system-threading-cancellationtoken)) .NET 7.0 + - [`static ValueTask HashDataAsync(Stream, Memory, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha384.hashdataasync#system-security-cryptography-sha384-hashdataasync(system-io-stream-system-memory((system-byte))-system-threading-cancellationtoken)) .NET 7.0 +- `SHA512` + - [`static bool TryHashData(ReadOnlySpan, Span, out int)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.tryhashdata) .NET 5.0 + - [`static byte[] HashData(byte[])`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdata#system-security-cryptography-sha512-hashdata(system-byte())) .NET 5.0 + - [`static byte[] HashData(ReadOnlySpan)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdata#system-security-cryptography-sha512-hashdata(system-readonlyspan((system-byte)))) .NET 5.0 + - [`static byte[] HashData(Stream)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdata#system-security-cryptography-sha512-hashdata(system-io-stream)) .NET 7.0 + - [`static int HashData(ReadOnlySpan, Span)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdata#system-security-cryptography-sha512-hashdata(system-readonlyspan((system-byte))-system-span((system-byte)))) .NET 5.0 + - [`static ValueTask HashDataAsync(Stream, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdataasync#system-security-cryptography-sha512-hashdataasync(system-io-stream-system-threading-cancellationtoken)) .NET 7.0 + - [`static ValueTask HashDataAsync(Stream, Memory, CancellationToken)`](https://learn.microsoft.com/dotnet/api/system.security.cryptography.sha512.hashdataasync#system-security-cryptography-sha512-hashdataasync(system-io-stream-system-memory((system-byte))-system-threading-cancellationtoken)) .NET 7.0 - `short` - [`static bool TryParse(ReadOnlySpan, IFormatProvider?, out short)`](https://learn.microsoft.com/dotnet/api/system.int16.tryparse#system-int16-tryparse(system-readonlyspan((system-char))-system-iformatprovider-system-int16@)) .NET 7.0 - [`static bool TryParse(string?, IFormatProvider?, out short)`](https://learn.microsoft.com/dotnet/api/system.int16.tryparse#system-int16-tryparse(system-string-system-iformatprovider-system-int16@)) .NET 7.0