簡體   English   中英

如何在C#中使用Bouncy Castle將X.509 v.3谷歌證書添加到項目中

[英]How to add X.509 v.3 google certificate to project with Bouncy Castle in c#

我一直在嘗試在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中加載證書(代碼的第一行)的替代方法是什么?

您可以將PCL項目的目標更改為.NETStandard。 在這之后,

System.Security.Cryptography.X509Certificates

支持。

您可以按照以下步驟操作:

  1. 右鍵單擊您的PCL項目
  2. 點擊屬性
  3. 點擊圖書館
  4. 單擊目標.NET平台標准
  5. 接受
  6. 轉到project.json並添加: "netstandard1.3": { "imports": "portable-net45+win8+wp8+wpa81"}
  7. 添加您的Nuget包。

對於步驟4,您必須刪除所有的Nu​​get軟件包,在步驟6之后,必須重新安裝它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM