草庐IT

c# - 将私钥与 .net 中的 X509Certificate2 类相关联

我正在编写一些代码来创建X509证书和公钥/私钥对。公钥被添加到证书中,并被发送到对其进行签名的CA。然后通过System.Security.Cryptography.X509Certificates.X509Certificate2类访问返回的证书。现在我想使用这个证书来启动与其他客户端的安全连接。因此我使用SslStream类。要启动SSL握手,我使用以下方法:server.AssociatedSslStream.AuthenticateAsServer(MyCertificate,//ClientCertificatetrue,//RequireCertificatefromco

c# - 使用私钥将 X509Certificate2 导出到字节数组

我的商店中有一个X509Certificate2证书,我想将其导出到字节数组和私钥。证书字节数组必须这样,当我稍后从字节数组导入证书时,私钥将包含私钥。我尝试了很多方法都没有成功导出带有私钥的证书。X509Storestore=newX509Store(StoreLocation.CurrentUser);store.Open(OpenFlags.ReadOnly);X509Certificate2cert=store.Certificates[1];byte[]certBytes=cert.GetRawCertData();//Obviouslydoesnotwork!是否可以将带私

c# - X509Certificate.CreateFromCertFile - 指定的网络密码不正确

我有一个.NET应用程序,我想将其用作客户端来调用SSLSOAPWeb服务。我已获得名为foo.pfx的有效客户端证书。证书本身有一个密码。我已将证书放在以下位置:C:\certs\foo.pfx要调用网络服务,我需要附加客户端证书。这是代码:publicX509CertificateGetCertificateFromDisk(){try{stringcertPath=ConfigurationManager.AppSettings["MyCertPath"].ToString();//thisevaluatesto"c:\\certs\\foo.pfx".Sofarsogood.X

c# - 如何设置对.NET X.509 证书私钥文件的读取权限

这是将pfx添加到证书存储区的代码。X509Storestore=newX509Store(StoreName.My,StoreLocation.LocalMachine);store.Open(OpenFlags.ReadWrite);X509Certificate2cert=newX509Certificate2("test.pfx","password");store.Add(cert);store.Close();但是,我找不到为NetworkService设置访问私钥的权限的方法。任何人都可以阐明一下吗?提前致谢。 最佳答案

c# - Azure 网站中的站点无法处理 X509Certificate2

我在Azure网站(不是托管服务)中有站点,我需要在那里处理带有私钥的.pfx证书。varx509Certificate2=newX509Certificate2(certificate,password);但我遇到了以下异常:System.Security.Cryptography.CryptographicException:Thesystemcannotfindthefilespecified.atSystem.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32hr)atSy

c# - 从 PKCS#12 字节数组构建 X509Certificate2 如何抛出 CryptographicException ("The system cannot find the file specified.")?

我试图从一个字节数组中的PKCS#12blob构造一个X509Certificate2并得到一个相当令人费解的错误。此代码在具有WindowsXP管理员权限的桌面应用程序中运行。堆栈跟踪如下,但我在尝试排除故障时迷路了,因为_LoadCertFromBlob被标记为[MethodImpl(MethodImplOptions.InternalCall)]。System.Security.Cryptography.CryptographicException:Thesystemcannotfindthefilespecified.atSystem.Security.Cryptography

c# - 是否可以仅使用 C# 以编程方式生成 X509 证书?

我们正在尝试使用C#和BouncyCastle以编程方式生成X509证书(包括私钥)图书馆。我们尝试使用thissamplebyFelixKollmann中的一些代码但证书的私钥部分返回null。代码和单元测试如下:usingSystem;usingSystem.Collections;usingOrg.BouncyCastle.Asn1;usingOrg.BouncyCastle.Asn1.X509;usingOrg.BouncyCastle.Crypto;usingOrg.BouncyCastle.Crypto.Generators;usingOrg.BouncyCastle.Cr

c# - X509 证书未在服务器上加载私钥文件

我正在使用GoogleAnalyticsAPI,我按照这个SO问题来设置OAuth:https://stackoverflow.com/a/13013265/1299363这是我的OAuth代码:publicvoidSetupOAuth(){varCert=newX509Certificate2(PrivateKeyPath,"notasecret",X509KeyStorageFlags.Exportable);varProvider=newAssertionFlowClient(GoogleAuthenticationServer.Description,Cert){Service

c# - X509证书构造函数异常

//certisanEFEntityand//cert.CertificatePKCS12isabyte[]withthecertificate.varcertificate=newX509Certificate(cert.CertificatePKCS12,"SomePassword");从我们的数据库加载证书时,在我们的暂存服务器(Windows2008R2/IIS7.5)上,我们得到这个异常:System.Security.Cryptography.CryptographicException:Aninternalerroroccurred.atSystem.Security.C

c# - X509Store Certificates.Find FindByThumbprint 问题

我在使用X509Store.Certificates.Find方法时遇到问题publicstaticX509Certificate2FromStore(StoreNamestoreName,StoreLocationstoreLocation,X509FindTypefindType,stringfindValue){X509Storestore=newX509Store(storeName,storeLocation);store.Open(OpenFlags.ReadOnly);try{//findValue="7a6fa503ab57b81d6318a51ca265e739a51