【问题标题】:RSACryptoServiceProvider.FromXmlString and RSA.FromXmlString not supported on .net core 2.x.net core 2.x 不支持 RSACryptoServiceProvider.FromXmlString 和 RSA.FromXmlString
【发布时间】:2020-01-21 03:59:10
【问题描述】:

我正在尝试使用 RSACryptoServiceProvider 和/或 RSA 对我的请求进行签名,但发现这些都不适用于 .net core 2.x,尽管 MS 文档是这样说的。

我想知道以前是否有人遇到过这个问题,是文档有问题还是我遗漏了什么。

using System.Security.Cryptography;
var privateKeyValidation = new RSACryptoServiceProvider();
privateKeyValidation.FromXmlString(PrivateKey);

如果我在 .net core 2.x 中运行,上面的代码将失败,并显示“此平台不支持操作”,但可以在 .net framework 4.5 和 .net core 3.1 上运行

我想知道我是否缺少一些程序集....

【问题讨论】:

  • 不要创建RSACryptoServiceProvider 实例,而是使用RSA.Create。你可能得不到传统的 Windows 加密服务提供商,但你会得到一个等效的实现
  • 我确实尝试使用 RSA.FromXmlString(),.net core 2.x 也不支持
  • 这能回答你的问题吗? .NET Core 2.0 RSA PlatformNotSupportedException

标签: c# asp.net-core .net-core cryptography


【解决方案1】:

好吧,显然微软没有正确检查他们的文档......

在同一页面上:https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rsa?view=netcore-3.1

它记录了该类在 .net 核心中不受支持,但还说它确实......陈述不正确且具有误导性。

真相就在这里: https://github.com/dotnet/core/issues/874

您只需在线复制某人的扩展方法(例如:https://github.com/dotnet/corefx/issues/23686)或编写自己的扩展方法.....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多