diff --git a/src/libraries/Microsoft.Bcl.Cryptography/src/System/Security/Cryptography/NetStandardShims.cs b/src/libraries/Microsoft.Bcl.Cryptography/src/System/Security/Cryptography/NetStandardShims.cs index 1e81d7a01b023c..d35c4738c5cb6e 100644 --- a/src/libraries/Microsoft.Bcl.Cryptography/src/System/Security/Cryptography/NetStandardShims.cs +++ b/src/libraries/Microsoft.Bcl.Cryptography/src/System/Security/Cryptography/NetStandardShims.cs @@ -100,25 +100,14 @@ internal static bool TryGetHashAndReset( Span destination, out int bytesWritten) { - int hashSize = hash.AlgorithmName.Name switch - { - nameof(HashAlgorithmName.MD5) => 128 >> 3, - nameof(HashAlgorithmName.SHA1) => 160 >> 3, - nameof(HashAlgorithmName.SHA256) => 256 >> 3, - nameof(HashAlgorithmName.SHA384) => 384 >> 3, - nameof(HashAlgorithmName.SHA512) => 512 >> 3, - _ => throw new CryptographicException(), - }; - - if (destination.Length < hashSize) + byte[] actual = hash.GetHashAndReset(); + + if (destination.Length < actual.Length) { bytesWritten = 0; return false; } - byte[] actual = hash.GetHashAndReset(); - Debug.Assert(actual.Length == hashSize); - actual.AsSpan().CopyTo(destination); bytesWritten = actual.Length; return true;