Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HashAlgorithms in CoreCLR

I'm trying use this class in my coreclr project but I can't seem to find the correct package for SHA256Managed. I have tried using System.Security.Cryptography.Algorithms": "4.0.0-beta-23409" but it doesn't contain the implementation of SHA2565Managed. Are there any other alternative for computing hash values in coreclr?

like image 909
Per Avatar asked Oct 20 '15 19:10

Per


1 Answers

You can use SHA256.Create() from namespace System.Security.Cryptography

(Assembly: 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));
}
like image 58
Kévin Chalet Avatar answered Oct 19 '22 00:10

Kévin Chalet