2015-10-20 1 views
15

Я пытаюсь использовать этот class в моем проекте coreclr, но я не могу найти правильный пакет для SHA256Managed. Я попытался использовать System.Security.Cryptography.Algorithms ":" 4.0.0-beta-23409 ", но он не содержит реализацию SHA2565Managed. Есть ли другая альтернатива для вычисления хеш-значений в coreclr?HashAlgorithms in CoreCLR

ответ

28

Вы можно использовать 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, 0, hash.Length/2)); 
} 
+0

это на самом деле в 'System.Security.Cryptography', не' System.Security.Cryptography.Algorithms' – Pavel

+0

@Pavel имя пакета [ 'System.Security.Cryptography .Algorithms'] (https://www.nuget.org/packages/System.Security.Cryptography.Algorithms/) и пространство имен 'System.Security.Cryptography'. – Pinpoint

+0

О, я вижу. Я не понимал, что это пакет NuGet. – Pavel

Смежные вопросы