【问题标题】:How to add X.509 v.3 google certificate to project with Bouncy Castle in c#如何将 X.509 v.3 谷歌证书添加到 C# 中的 Bouncy Castle 项目中
【发布时间】:2017-05-26 00:00:31
【问题描述】:

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

【问题讨论】:

    标签: c# xamarin x509certificate2 service-accounts


    【解决方案1】:

    您可以将 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 包。

    对于第 4 步,您必须删除所有 Nuget 包,在第 6 步之后,您必须重新安装它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-04
      • 1970-01-01
      • 2011-02-11
      • 2017-08-14
      • 2011-02-04
      相关资源
      最近更新 更多