2016-06-14 62 views
2

我一直試圖在Xamarin.iOS上使用Google的服務帳戶。 System.Security.Cryptography.X509Certificates不支持PCL項目,所以我需要一種不同的方式(如Bouncy Castle或PCLCrypto)將X509Certificate加載到項目中。基本上,作爲谷歌的文檔中,提取證書的方法是如下:如何將X.509 v.3谷歌證書添加到C中的Bouncy Castle項目中#

var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable); 

     ServiceAccountCredential credential = new ServiceAccountCredential(
      new ServiceAccountCredential.Initializer(serviceAccountEmail) 
      { 
       Scopes = new[] { PlusService.Scope.PlusMe } 
      }.FromCertificate(certificate)); 

的問題是,什麼是充氣城堡加載證書(代碼的第一行)的替代方式?

回答

0

您可以將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之後,您必須重新安裝它們。