简体   繁体   中英

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

I have been trying to use Google's service account on Xamarin.iOS. System.Security.Cryptography.X509Certificates is not supported for PCL projects so i need a different way(like Bouncy Castle or PCLCrypto) to load X509Certificate into the project. Basically, as in the Google's document, the way of extracting the certificate is as following:

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

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

The question is that, what is the alternative way of loading certificate(the first line of the code) in Bouncy Castle ?

You can change the Target of your PCL project to .NETStandard. After this,

System.Security.Cryptography.X509Certificates

is supported.

You can do it with the following steps:

  1. Right-click on your PCL project
  2. Click on Properties
  3. Click on Library
  4. Click on Target .NET Platform Standard
  5. Accept
  6. Goto project.json and add: "netstandard1.3": { "imports": "portable-net45+win8+wp8+wpa81"}
  7. Add your Nuget package.

For step 4 you must remove all your Nuget packages and after step 6 you must reinstall their.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM