Я не знаю этого языка программирования, но вот код от OidcClient
https://github.com/IdentityModel/IdentityModel.OidcClient2
public bool ValidateHash(string data, string hashedData, string signatureAlgorithm)
{
var hashAlgorithm = GetMatchingHashAlgorithm(signatureAlgorithm);
using (hashAlgorithm)
{
var hash = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(data));
byte[] leftPart = new byte[hashAlgorithm.HashSize / 16];
Array.Copy(hash, leftPart, hashAlgorithm.HashSize / 16);
var leftPartB64 = Base64Url.Encode(leftPart);
var match = leftPartB64.Equals(hashedData);
if (!match)
{
_logger.LogError($"data ({leftPartB64}) does not match hash from token ({hashedData})");
}
return match;
}
}
public HashAlgorithm GetMatchingHashAlgorithm(string signatureAlgorithm)
{
var signingAlgorithmBits = int.Parse(signatureAlgorithm.Substring(signatureAlgorithm.Length - 3));
switch (signingAlgorithmBits)
{
case 256:
_logger.LogDebug("SHA256");
return SHA256.Create();
case 384:
_logger.LogDebug("SHA384");
return SHA384.Create();
case 512:
_logger.LogDebug("SHA512");
return SHA512.Create();
default:
return null;
}
}