2015-10-20 9 views
15

Sto provando a usare questo class nel mio progetto coreclr ma non riesco a trovare il pacchetto corretto per SHA256Managed. Ho provato a utilizzare System.Security.Cryptography.Algorithms ":" 4.0.0-beta-23409 "ma non contiene l'implementazione di SHA2565Managed. Esistono altre alternative per calcolare i valori hash in coreclr?HashAlgorithms in CoreCLR

risposta

28

Si può usare SHA256.Create() (da 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)); 
} 
+0

in realtà è in 'System.Security.Cryptography', non' System.Security.Cryptography.Algorithms' – Pavel

+0

@Pavel il nome del pacchetto è [ 'System.Security.Cryptography .Algorithms'] (https://www.nuget.org/packages/System.Security.Cryptography.Algorithms/) e lo spazio dei nomi 'System.Security.Cryptography'. – Pinpoint

+0

Oh, capisco. Non avevo capito che era un pacchetto NuGet. – Pavel

Problemi correlati