我一直在尝试在 Xamarin.iOS 上使用 Google 的服务帐户。 PCL 项目不支持 System.Security.Cryptography.X509Certificates,因此我需要一种不同的方式(如 Bouncy CaSTLe 或 PCLCrypto)将 X509Certificate 加载到项目中。基本上,在谷歌的文档中,提取证书的方式如下:
var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { PlusService.Scope.PlusMe }
}.FromCertificate(certificate));
问题是,在 Bouncy CaSTLe 中加载证书(代码的第一行)的替代方法是什么?
最佳答案
您可以将 PCL 项目的目标更改为 .NETStandard。在此之后,
System.Security.Cryptography.X509Certificates
支持。
您可以通过以下步骤完成:
- 右键单击您的 PCL 项目
- 点击属性
- 点击图书馆
- 点击“目标 .NET 平台标准”
- 接受
- 转到 project.json 并添加:
"netstandard1.3": { "imports": "portable-net45+win8+wp8+wpa81"}
- 添加您的 Nuget 包。
对于第 4 步,您必须删除所有 Nuget 包,在第 6 步之后,您必须重新安装它们。
关于c# - 如何在 C# 中使用 Bouncy CaSTLe 将 X.509 v.3 谷歌证书添加到项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37820804/