.net standard 2.0 and System.Security.Cryptography

2019-04-13 05:43发布

问题:

Looking at System.Security.Cryptography.ProtectedData.Protect @ https://docs.microsoft.com/en-gb/dotnet/api/

as we looking to port a library from 4.7 to .net standard 2.0 library where .net core 2.0 will use it. So I did a search and it only available in full framework and .net core

My question is why is it not available in .Net Stanard 2.0?

I would have taught if it can be used in for example 4.7 and .net core 2.0 then it would be part of .Net Standard 2.0

回答1:

This API is not available "in" .NET Standard 2.0, but it is available "for" .NET Standard 2.0 as a "Platform Extension" which means that there is a NuGet package you have to add to get support for it.

If you add a reference to the System.Security.Cryptography.ProtectedData NuGet package, you can develop a .NET Standard library that uses these APIs.

However, this support only works when run on Windows, since those APIs are described as

Provides access to Windows Data Protection Api.

so it won't work on platforms other than Windows. Depending on your needs, this may be just fine.

If you are looking to implement similar concepts cross-platform, I suggest looking into the ASP.NET Core Data Protection APIs which could also be used outside of the context of an ASP.NET Core app since it is made out of NuGet packages that provide cryptographic logic and key storage solutions (e.g. directory, windows certificate stores, Azure KeyVault).



回答2:

Firstly

I can't answer for Microsoft

tl;dr

A lot of these questions can be answered with: if you need APIs found in .NET Framework, use the .NET Framework.

Longer form answer

A large number of the APIs found in .NET Framework either rely on underlying Windows libraries (which aren't available on MacOs or Linux distros) or they are currently too complex to implement, as such they are not available for .NET Core.

If there is an API you need access to which is only available in .NET Framework, then (for the time being) it's best to use .NET Framework rather than .NET Core/Mono/etc.

If you have a compelling reason for something to be included in .NET Standard, then I would head over to the .NET Standard GitHub repo and ask for it to be implemented there.