如何在c#中添加X.509 v.3谷歌证书与Bouncy Castle项目

时间:2016-06-14 19:45:32

标签: c# xamarin x509certificate2 service-accounts

我一直在尝试在Xamarin.iOS上使用Google的服务帐户。 PCL项目不支持System.Security.Cryptography.X509Certificates,因此我需要一种不同的方式(如Bouncy Castle或PCLCrypto)将X509Certificate加载到项目中。基本上,与Google的文档一样,提取证书的方式如下:

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中加载证书(代码的第一行)的替代方法是什么?

1 个答案:

答案 0 :(得分:0)

您可以将PCL项目的目标更改为.NETStandard。在此之后,

  

System.Security.Cryptography.X509Certificates

支持

您可以按照以下步骤执行此操作:

  1. 右键单击您的PCL项目
  2. 点击“属性”
  3. 点击图书馆
  4. 单击Target .NET Platform Standard
  5. 接受
  6. 转到project.json并添加:"netstandard1.3": { "imports": "portable-net45+win8+wp8+wpa81"}
  7. 添加您的Nuget包。
  8. 对于第4步,您必须删除所有Nuget包,在步骤6之后,您必须重新安装它们。

相关问题