我正在我的coreclr项目中尝试使用此class,但似乎找不到适用于SHA256Managed的正确软件包。我已经尝试过使用System.Security.Cryptography.Algorithms“:” 4.0.0-beta-23409“,但其中不包含SHA2565Managed的实现。在coreclr中还可以使用其他方法来计算哈希值吗?

最佳答案

您可以使用命名空间SHA256.Create()中的System.Security.Cryptography
(程序集:System.Security.Cryptography.Algorithms)

using (var algorithm = SHA256.Create())
{
    // Create the at_hash using the access token returned by CreateAccessTokenAsync.
    var hash = algorithm.ComputeHash(Encoding.ASCII.GetBytes(response.AccessToken));

    // Note: only the left-most half of the hash of the octets is used.
    // See http://openid.net/specs/openid-connect-core-1_0.html#CodeIDToken
    identity.AddClaim(JwtRegisteredClaimNames.AtHash, Base64UrlEncoder.Encode(hash, 0, hash.Length / 2));
}

关于asp.net-core - CoreCLR中的Hash算法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33245247/

10-12 00:25
查看更多