Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make hasher static and readonly in CryptographicExtensions #363

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@

using System.Security.Cryptography;
using System.Text;
using System.Threading;

namespace Microsoft.OpenApi.OData.Common
{
internal static class CryptographyExtensions
{
private static readonly ThreadLocal<SHA256> hasher = new (SHA256.Create);

/// <summary>
/// Calculates the SHA256 hash for the given string.
/// </summary>
/// <returns>A 64 char long hash.</returns>
public static string GetHashSHA256(this string input)
{
Utils.CheckArgumentNull(input, nameof(input));

var hasher = new SHA256CryptoServiceProvider();

var inputBytes = Encoding.UTF8.GetBytes(input);
var hashBytes = hasher.ComputeHash(inputBytes);
var hashBytes = hasher.Value.ComputeHash(inputBytes);
var hash = new StringBuilder();
foreach (var b in hashBytes)
{
Expand Down