微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net-core – CoreCLR中的哈希算法

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

解决方法

您可以使用SHA256.Create()(从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,hash.Length / 2));
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐