【问题标题】:System.Security.Cryptography.X509Certificates.X509Certificate2.GetECDsaPublicKey NotImplementedSystem.Security.Cryptography.X509Certificates.X509Certificate2.GetECDsaPublicKey 未实现
【发布时间】:2020-08-26 11:34:06
【问题描述】:

我们在 .Net Core Web api 中创建了一个签名,在 .pfx 证书文件上使用 X509Certificate2.GetECDsaPrivateKey,并且需要在我们的 Xamarin Android 应用程序中使用公钥 (.crt) 验证此签名。我可以在普通的 Windows .Net Framework 4.6.1 应用程序上运行代码并且它可以工作。如果我将框架版本更改为更低的版本,我的应用程序将无法编译,因为 GetECDsaPublicKey 方法仅在 4.6.1 中实现。在我的 Xamarin 应用程序中,我可以编译该应用程序并运行它,但是一旦我到达执行 GetECDsaPublicKey 方法的行,我就会得到一个 NotImplemented 异常。互联网上几乎没有这方面的信息,除了 Microsoft 文档,它在任何情况下都没有提供太多信息。谁能阐明为什么会发生此错误?下面是加载证书和验证签名的几行代码(我去掉了一些不必要的错误检查代码):

string FileName = "public_key.crt";
string certPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), FileName);
System.Security.Cryptography.X509Certificates.X509Certificate2 certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(certPath);
System.Security.Cryptography.ECDsa eCDsa = certificate.GetECDsaPublicKey(); // This line causes the exception

即使只是执行这一行,也会出现同样的错误:

System.Security.Cryptography.ECDsa eCDsa = System.Security.Cryptography.ECDsa.Create();

【问题讨论】:

    标签: c# xamarin.android .net-standard .net-framework-version system.security


    【解决方案1】:

    因此,如果有人遇到这个问题也很苦恼,有一篇帖子可以回答这个问题 - Are ECDSA and ECDH available for mono?

    遗憾的是,我们将不得不使用不同的加密/签名算法或使用 BouncyCastle 之类的东西...

    【讨论】:

      猜你喜欢
      • 2021-07-07
      • 2011-10-05
      • 1970-01-01
      • 2015-10-18
      • 2014-12-05
      • 2016-09-10
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      相关资源
      最近更新 更多