CoreCLR中的哈希算法

Per*_*Per 20 coreclr asp.net-core

我正在尝试在我的coreclr项目中使用这个,但我似乎找不到SHA256Managed的正确包.我曾尝试使用System.Security.Cryptography.Algorithms":"4.0.0-beta-23409"但它不包含SHA2565Managed的实现.在coreclr中是否还有其他计算哈希值的替代方法?

Kév*_*let 39

您可以使用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));
}
Run Code Online (Sandbox Code Playgroud)