我们在 .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();