Questions tagged [x509certificate2]

.NET Class for handling X.509 Certificates

792 questions
42
votes
5 answers

X509 certificate not loading private key file on server

I'm using the Google Analytics API and I followed this SO question to set up the OAuth: https://stackoverflow.com/a/13013265/1299363 Here is my OAuth code: public void SetupOAuth () { var Cert = new X509Certificate2( PrivateKeyPath, …
acurcie
  • 888
  • 2
  • 8
  • 22
41
votes
4 answers

Exporting a Certificate as BASE-64 encoded .cer

I am trying to export a cert without the private key as as BASE-64 encoded file, same as exporting it from windows. When exported from windows I am able to open the .cer file in notepad. When I try the following and open on notepad I get binary…
Saif Khan
  • 17,334
  • 28
  • 97
  • 144
38
votes
5 answers

How can constructing an X509Certificate2 from a PKCS#12 byte array throw CryptographicException("The system cannot find the file specified.")?

I'm trying to construct an X509Certificate2 from a PKCS#12 blob in a byte array and getting a rather puzzling error. This code is running in a desktop application with administrator rights on Windows XP. The stack trace is as follows, but I got…
Jeffrey Hantin
  • 33,679
  • 7
  • 71
  • 92
37
votes
6 answers

Site in Azure Websites fails processing of X509Certificate2

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…
Roman Oleynik
  • 619
  • 1
  • 5
  • 12
30
votes
2 answers

How to create a valid, self-signed X509Certificate2 programmatically, not loading from file in .NET Core

What I currently do is that I use OpenSSL to generate PFX file. This is causing an unwanted dependency, especially for Windows users. So I found some examples on how to create your own certificate using BouncyCastle, but this library is not .NET…
Wapac
  • 3,646
  • 2
  • 17
  • 28
29
votes
2 answers

Export X509Certificate2 to byte array with the Private key

I have an X509Certificate2 certificate in my store that I would like to export to a byte array with the private key. The certificate byte array has to be so that when I then later would import the certificate from the byte array the private key…
Erik Larsson
  • 2,339
  • 4
  • 14
  • 14
26
votes
1 answer

X509Certificate2 makes IIS crash

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…
Pauli Østerø
  • 6,728
  • 1
  • 28
  • 48
25
votes
2 answers

HTTPS request fails using HttpClient

I am using the following code and get HttpRequestException exception: using (var handler = new HttpClientHandler()) { handler.ClientCertificateOptions = ClientCertificateOption.Manual; handler.SslProtocols = SslProtocols.Tls12; …
hypercodeplace
  • 2,506
  • 6
  • 21
  • 31
25
votes
6 answers

how to create a completely new x509Certificate2 in .net?

I google it from web, find many samples to generate a new x509Certificate2 from a file in .net, but there is no one sample to show how to generate a completely new x509Certificate2 from the beginning in .net. Is there any one that can tell me how to…
travellover
  • 261
  • 1
  • 4
  • 5
23
votes
4 answers

How to programmatically import a pfx with a chain of certificates into the certificate store?

I am trying to programmatically import a X509 certificate (pfx / PKCS#12) in my local machine's certificate store. This particular certificate has a chain of certificates, the certification path looks something like this: Root certificate…
Edwin de Koning
  • 13,489
  • 6
  • 52
  • 71
23
votes
4 answers

How to create a minimal dummy X509Certificate2?

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…
Cephron
  • 1,547
  • 1
  • 18
  • 26
20
votes
3 answers

C# and dotnet 4.7.1 not adding custom certificate for TLS 1.2 calls

I have the following C# code, constructing an https call with a custom certificate. When using Tls 1.1, the call works fine. When using Tls 1.2 the call breaks. I using curl, using tls 1.2 works fine as well. C# Code: X509Certificate2Collection…
Stephan Møller
  • 1,023
  • 17
  • 34
20
votes
2 answers

how to load password protected certificates from the X509Store?

I am building an ACS protected Azure WCF service that will require clients to authenticate via a certificate. I would like the client (and the server) to load their respective password certs from the X509Store instead of from the file system. I am…
Pete Maroun
  • 1,865
  • 1
  • 16
  • 27
19
votes
7 answers

PowerShell Get Certificate Thumbprint with Password PFX File

I'm trying to get the thumbprint of a password protected pfx file using this code: function Get-CertificateThumbprint { # # This will return a certificate thumbprint, null if the file isn't found or throw an exception. # param ( …
flipcode
  • 411
  • 2
  • 5
  • 18
18
votes
8 answers

How do you parse the Subject Alternate Names from an X509Certificate2?

Is there an easy way to get the Subject Alternate Names from an X509Certificate2 object? foreach (X509Extension ext in certificate.Extensions) { if (ext.Oid.Value.Equals(/* SAN OID */"2.5.29.17")) { …
noctonura
  • 11,595
  • 10
  • 45
  • 79
1
2 3
52 53