Skip to content
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