简体   繁体   English

如何在C#中使用Bouncy Castle将X.509 v.3谷歌证书添加到项目中

[英]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. 我一直在尝试在Xamarin.iOS上使用Google的服务帐户。 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. PCL项目不支持System.Security.Cryptography.X509Certificates,因此我需要以其他方式(例如Bouncy Castle或PCLCrypto)将X509Certificate加载到项目中。 Basically, as in the Google's document, the way of extracting the certificate is as following: 基本上,就像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));

The question is that, what is the alternative way of loading certificate(the first line of the code) in Bouncy Castle ? 问题是,在Bouncy Castle中加载证书(代码的第一行)的替代方法是什么?

You can change the Target of your PCL project to .NETStandard. 您可以将PCL项目的目标更改为.NETStandard。 After this, 在这之后,

System.Security.Cryptography.X509Certificates System.Security.Cryptography.X509Certificates

is supported. 支持。

You can do it with the following steps: 您可以按照以下步骤操作:

  1. Right-click on your PCL project 右键单击您的PCL项目
  2. Click on Properties 点击属性
  3. Click on Library 点击图书馆
  4. Click on Target .NET Platform Standard 单击目标.NET平台标准
  5. Accept 接受
  6. Goto project.json and add: "netstandard1.3": { "imports": "portable-net45+win8+wp8+wpa81"} 转到project.json并添加: "netstandard1.3": { "imports": "portable-net45+win8+wp8+wpa81"}
  7. Add your Nuget package. 添加您的Nuget包。

For step 4 you must remove all your Nuget packages and after step 6 you must reinstall their. 对于步骤4,您必须删除所有的Nu​​get软件包,在步骤6之后,必须重新安装它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# 如何使用 Bouncy Castle 而不是 x509certificate2 在 Asp.net 5 中使用 S/Mime - C# How to S/Mime in Asp.net 5 with Bouncy Castle instead of x509certificate2 如何将 Bouncy Castle X509Crl C# 中的 CRL 编号解析为 BigInteger - How to parse CRL Number in Bouncy Castle X509Crl C# as BigInteger 在C#中,使用x.509证书签署xml并检查签名 - In C#, sign an xml with a x.509 certificate and check the signature C#解密与X.509证书没有私钥 - C# Decryption with X.509 certificate without private key 如何读取 Pem 证书和私钥文件并创建 Bouncy Castle X509Certificate 和 Bouncy Castle AsymmetricKeyParameter dotnet 核心? - How to Read a Pem Cert and Private Key Files and create Bouncy Castle X509Certificate and Bouncy Castle AsymmetricKeyParameter dotnet core? 如何使用Compact Framework在C#中验证X.509证书 - How to validate X.509 Certificate in C# using Compact Framework 如何在 C#/Xamarin 中使用带有来自 android 钥匙串的私钥的 X.509 证书? - How can I use an X.509 certificate with private key from the android keychain in C#/Xamarin? 充气城堡的CMS签名X509证书 - CMS Signature X509 Certificate with Bouncy Castle 如何从Bouncy Castle创建X509证书以与AuthenticateAsServer一起使用? - How to create a X509 certificate from Bouncy Castle for use with AuthenticateAsServer? 如何判断X.509证书是否可导出? - How to tell if X.509 Certificate is Exportable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM