System.Security.Cryptography.SHA256Cng .NET Core

Viewed 6368

I have one .net core app as console and I'm trying to get some values from Azure Db. This code works perfect on .NET Framework (standard) and I always get my data but I need to work with .NET Core. In short, I have one method which GetConfig from another (.dll) and everytime I get exception:

Exception

System.AggregateException: 'One or more errors occurred. (Could not load type 'System.Security.Cryptography.SHA256Cng' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.)'

I know .NET Core has System.Core but it doesn't have "SHA256Cng", just "SHA256". Maybe Can I use .net framework .dll or is there another way to solve this problem? PS. Need to use only .NET Core (.net console app and other).

Thanks.

Method

public ITenantConfigurationProvider CreateTenantConfigurationProvider(ITenantClient client, string tenantId)
        {
            return client.GetConfigAsync(tenantId).Result;
        }
3 Answers

Use SHA256.Create() instead of new SHA256Cng()

I believe the SHA256 class is part of 'System.Security.Cryptography'. Do you have that library?

The only solution I found is to create a .NET framework project because .NET Core does not support this class.

Related