加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-15 23:27:57 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试在我的coreclr项目中使用这个 class,但是似乎找不到SHA256Managed的正确包.我已经尝试使用System.Security.Cryptography.Algorithms“:”4.0.0-beta-23409“,但它不包含SHA2565Managed的实现.还有其他替代方案来计算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));
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读