本文介绍了.NET Standard 2.0 和 System.Security.Cryptography.ProtectedData.Protect的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看 System.Security.Cryptography.ProtectedData.Protect@ https://docs.microsoft.com/en-gb/dotnet/api/

因为我们希望将库从 .NET Framework 4.7 移植到 .NET Standard 2.0 以供 .NET Core 2.0 使用.我进行了搜索,它仅在完整的 .NET Framework 和 .NET Core 中可用.

as we are looking to port a library from .NET Framework 4.7 to .NET Standard 2.0 to be used by .NET Core 2.0.I did a search and it only available in the full .NET Framework and .NET Core.

我的问题是,为什么它在 .NET Standard 2.0 中不可用?

My question is, why is it not available in .NET Standard 2.0?

我本以为如果它可以用于 .NET Framework 4.7 和 .NET Core 2.0,那么它也将成为 .NET Standard 2.0 的一部分

I would have thought that if it can be used in, for example, .NET Framework 4.7 and .NET Core 2.0 then it would also be part of .NET Standard 2.0

推荐答案

此 API 在 .NET Standard 2.0 中不可用,但在 .NET Standard 2.0 中作为平台扩展"可用,这意味着您必须添加一个 NuGet 包才能获得对它的支持.

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.

如果添加对 System.Security.Cryptography.ProtectedData NuGet 包的引用,则可以开发使用这些 API 的 .NET Standard 库.

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

但是,此支持仅在 Windows 上运行时有效,因为这些 API 被描述为

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

提供对 Windows 数据保护 Api 的访问.

所以它不能在 Windows 以外的平台上运行.根据您的需要,这可能没问题.

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

如果您希望跨平台实现类似的概念,我建议查看 ASP.NET Core 数据保护 API 也可以在 ASP.NET Core 应用程序的上下文之外使用,因为它由提供加密逻辑和密钥存储解决方案的 NuGet 包组成(例如目录、Windows 证书存储、Azure KeyVault).

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).

这篇关于.NET Standard 2.0 和 System.Security.Cryptography.ProtectedData.Protect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:00