Tag: x509certificate2

如何以编程方式将带有证书链的pfx导入证书存储区?

我正在尝试以编程方式在我的本地计算机的证书存储中导入X509证书(pfx / PKCS#12)。 此特定证书具有一系列证书,证书路径如下所示: 根证书CA. 组织证书CA. 组织2证书CA. 我的证书 我使用的代码如下所示: cert = new X509Certificate2(pathToCert, password); if (cert != null) { var store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadWrite); if (!store.Certificates.Contains(cert)) { store.Add(cert); } } 此代码确实导入了证书,但它似乎忽略了链。 如果我检查商店中的证书,则证书路径仅显示: 我的证书 但是,当我手动导入pfx时,它确实显示完整路径。 我在这里跳过一步,还是我错过了一些参数? 有人可以对此有所了解吗?

导出X.509证书没有私钥

我认为这很简单,但显然不是。 我安装了一个具有私钥,可导出的证书,我想以编程方式仅使用公钥导出它。 换句话说,我想要一个等效于在通过certmgr导出并导出到.CER时选择“不导出私钥”的结果。 似乎所有X509Certificate2.Export方法都会导出私钥(如果存在),如PKCS#12,这与我想要的相反。 有没有办法使用C#来实现这一目标,还是我需要开始深入了解CAPICOM?

Azure网站中的站点无法处理X509Certificate2

我在Azure网站(不是托管服务)中有网站,我需要在那里处理带有私钥的.pfx证书。 var x509Certificate2 = new X509Certificate2(certificate, password); 但我面临以下例外: System.Security.Cryptography.CryptographicException: The system cannot find the file specified. at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags) 在文章http://blog.tylerdoerksen.com/2013/08/23/pfx-certificate-files-and-windows-azure-websites/我发现它发生是因为默认情况下系统使用用户的本地目录存储密钥。 但Azure网站没有本地用户配置文件目录。 在同一篇文章中,作者建议使用X509KeyStorageFlags.MachineKeySet标志。 var […]

将私钥/公钥从X509证书导出到PEM

有没有方便的方法从使用.NET Core的 PEM格式的.p12证书导出私钥/公钥? 没有在低级别操作字节? 我用谷歌搜索了几个小时,几乎没有任何东西可用于.net核心,或者没有记录在任何地方.. 我们有一个X509Certificate2 var cert = new X509Certificate2(someBytes, pass); var privateKey = cert.GetRSAPrivateKey(); var publicKey = cert.GetRSAPublicKey(); // assume everything is fine so far 现在我需要将密钥导出为两个单独的PEM密钥。 我已经在BouncyCastle中尝试过PemWriter ,但这些类型与Core的System.Security.Cryptography不兼容..没有运气。 – -编辑 – – 换句话说,我找到了一种如何写这个的方法: $ openssl pkcs12 -in path/to/cert.p12 -out public.pub -clcerts -nokeys $ openssl pkcs12 -in path/to/cert.p12 -out private.key -nocerts 有人有想法吗? 谢谢 …

在C#中,使用x.509证书签署xml并检查签名

我正在尝试使用x.509证书签署XML文件,我可以使用私钥对文档进行签名,然后使用CheckSignature方法(它具有接收证书作为参数的重载)来validation签名。 问题是validation签名的用户必须拥有证书,我关心的是,如果用户拥有证书,那么他可以访问私钥,据我所知,这是私有的,应该只对用户可用谁签字。 我错过了什么? 谢谢你的帮助。

如何在Azure Key Vault中序列化和反序列化PFX证书?

我有一堆字符串和pfx证书,我想存储在Azure Key保险库中,只允许用户/应用程序获取它们。 将字符串存储为Secret并不难,但是如何以可以检索它的方式序列化证书并在C#中反序列化为X509Certificate2对象? 我试着将它存储为钥匙。 这是Azure powershell代码 $securepfxpwd = ConvertTo-SecureString -String ‘superSecurePassword’ -AsPlainText -Force $key = Add-AzureKeyVaultKey -VaultName ‘UltraVault’ -Name ‘MyCertificate’ -KeyFilePath ‘D:\Certificates\BlaBla.pfx’ -KeyFilePassword $securepfxpwd 但是当我试图用GetKeyAsync方法获取它时,我无法使用它。