x509certificate2

X509Certificate2 validation on web service

谁说胖子不能爱 提交于 2019-12-01 07:32:51
问题 I'm developing WCF web service that checks if a certificate in XML signature is valid. XML is signed with qualified and valid X509 certificate. While I am running service within Visual Studio development environment X509Certificate2.Verify() and X509Chain.Build() methods return TRUE. But when I publish my service under IIS these methods return FALSE. What I am doing wrong or what is missing? Here is my validation code: public static void VerifyXml(XmlDocument xDoc) { // Create a new SignedXml

How to get private key from PKCS#12 (.p12) file using C#

蹲街弑〆低调 提交于 2019-12-01 06:16:32
问题 Im trying to sign some data using PKCS#12 certificate ,however i have problem with obtaining private key from PKCS#12 (.p12) file. public byte[] sign(string text) { string password = "1111"; X509Certificate2 cert = new X509Certificate2("c:\\certificate.p12",password); byte[] certData = cert.Export(X509ContentType.Pfx,password); X509Certificate2 newCert = new X509Certificate2(certData, password); RSACryptoServiceProvider crypt = (RSACryptoServiceProvider)newCert.PrivateKey; SHA1Managed sha1 =

C# Generate a non self signed client CX509Certificate Request without a CA using the certenroll.dll

旧巷老猫 提交于 2019-12-01 00:45:09
I have a self signed root certificate that I generated in C# using CERTENROLL.dll's CX509CertificateRequest Certificate functionality. I would like to write a function that generates client certificates signed by my root using the same API. However the only CertEnroll option I can find that does not generate a self signed certificate requires a authenticated CA. There seems to be a flag for setting a SignerCertificate but it always fails to initialize. //Initialize cert var cert = new CX509CertificateRequestCertificate(); //take care of signer cert.Issuer = issuen; CSignerCertificate sc = new

How to create a minimal dummy X509Certificate2?

久未见 提交于 2019-11-30 11:08:47
I'm unit testing a .NET application; some of the unit tests involve programmatically generating X509Certificate2 objects. I don't care about actual signing/private key/validation stuff, I'd just like to have an object that doesn't throw exceptions when its fields are examined. I tried using the parameterless constructor, but then a whole bunch of fields throw exceptions when accessed. As seen in the debugger: SubjectName = '(new System.Collections.Generic.Mscorlib_CollectionDebugView(result.Certificates)).Items[0].SubjectName' threw an exception of type 'System.Security.Cryptography

HTTPS request fails using HttpClient

核能气质少年 提交于 2019-11-30 10:59:35
I am using the following code and get HttpRequestException exception: using (var handler = new HttpClientHandler()) { handler.ClientCertificateOptions = ClientCertificateOption.Manual; handler.SslProtocols = SslProtocols.Tls12; handler.ClientCertificates.Add(new X509Certificate2(@"C:\certificates\cert.pfx")); // I also tried to add another certificates that was provided to https access // by administrators of the site, but it still doesn't work. //handler.ClientCertificates.Add(new X509Certificate2(@"C:\certificates\cert.crt")); //handler.ClientCertificates.Add(new X509Certificate2(@"C:

Importing ECC-based certificate from the Windows Certificate Store into CngKey

坚强是说给别人听的谎言 提交于 2019-11-30 08:57:48
问题 How can I get the public/private keys from an ECC-based X509Certificate2 's into CngKey 's for use with ECDsaCng and ECDiffieHellmanCng ? I'm currently using RSA 2048 bit key pairs to sign/encrypt stuff. I'm doing this by pulling the certificates from the X509Store where they are securely stored with private keys marked as non-exportable. I would like to convert the current implementation to use ECDSA and ECDH so that I can use smaller key sizes for equivalent security. I've successfully

Site in Azure Websites fails processing of X509Certificate2

一曲冷凌霜 提交于 2019-11-30 06:34:00
问题 I have site in Azure Websites (not Hosted Service) and I need processing .pfx certificates with private key there. var x509Certificate2 = new X509Certificate2(certificate, password); But I was faced with follow exception: 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[]

Exporting X.509 certificate WITHOUT private key

萝らか妹 提交于 2019-11-29 09:34:47
I thought this would be straightforward but apparently it isn't. I have a certificate installed that has a private key, exportable, and I want to programmatically export it with the public key ONLY. In other words, I want a result equivalent to selecting "Do not export the private key" when exporting through certmgr and exporting to .CER. It seems that all of the X509Certificate2.Export methods will export the private key if it exists, as PKCS #12, which is the opposite of what I want. Is there any way using C# to accomplish this, or do I need to start digging into CAPICOM? For anyone else who

Generating self-signed certificate without external libraries

北战南征 提交于 2019-11-29 08:44:39
I'm curious to know if there's a simplish way to create a self-signed certificate comparable to the below New-SelfSignedCertificate command (other providers are OK too, for instance). I want to use only the .NET libraries without P/Invoke or external libraries such as Bouncy Castle or without calling PowerShell from the application. New-SelfSignedCertificate -DnsName $certificateName -CertStoreLocation $certificateStore -KeyExportPolicy Exportable -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -NotAfter $certificateNotAfter I suppose the simplest alternative would be to call

X509Certificate2 makes IIS crash

穿精又带淫゛_ 提交于 2019-11-29 02:56:47
When newing up an instance of X509Certificate2(string, string) my IIS process simply crashes. No .Net exception, no nothing, except of this in my event log Faulting application name: w3wp.exe, version: 8.0.9200.16384, time stamp: 0x50108835 Faulting module name: ntdll.dll, version: 6.2.9200.16420, time stamp: 0x505ab405 Exception code: 0xc0000374 Fault offset: 0x00000000000ea485 Faulting process id: 0x102c Faulting application start time: 0x01ce10301e250c4d Faulting application path: c:\windows\system32\inetsrv\w3wp.exe Faulting module path: C:\Windows\SYSTEM32\ntdll.dll Report Id: 5e55321c