Questions tagged [x509certificate2]

.NET Class for handling X.509 Certificates

922 questions
49
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
  • 18,402
  • 29
  • 102
  • 147
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, …
wholol
  • 918
  • 2
  • 9
  • 22
40
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
  • 35,734
  • 7
  • 75
  • 94
38
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
  • 4,058
  • 2
  • 20
  • 33
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
32
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,639
  • 4
  • 16
  • 14
31
votes
1 answer

What is the rationale for all the different X509KeyStorageFlags?

Today, a colleague hit yet another bug related to these! I've found these flags really frustrating in past myself, because if you get them slightly wrong while instantiating X509Certificate2 objects, or exporting them, or saving them in an X509Store…
Tim Lovell-Smith
  • 15,310
  • 14
  • 76
  • 93
31
votes
6 answers

How to create a completely new x509Certificate2 in .Net?

I google it from web, find many examples to generate a new x509Certificate2 from a file in .Net, but there is no example 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
  • 331
  • 1
  • 4
  • 5
27
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,878
  • 2
  • 31
  • 48
26
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
  • 621
  • 2
  • 9
  • 19
26
votes
3 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
  • 2,045
  • 2
  • 18
  • 27
25
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,577
  • 1
  • 19
  • 26
25
votes
2 answers

'Cannot find the requested object' exception while creating X509Certificate2 from string

I am trying to create X509Certificate2 from string. Let me show an example: string keyBase64String = Convert.ToBase64String(file.PKCS7); var cert = new X509Certificate2(Convert.FromBase64String(keyBase64String)); and keyBase64String has a such…
StepUp
  • 36,391
  • 15
  • 88
  • 148
25
votes
4 answers

Export private/public keys from X509 certificate to PEM

is there any convenient way to export private/public keys from .p12 certificate in PEM format using .NET Core? Without manipulating with bytes at low level? I googled for hours and almost nothing is usable in .net core or it isn't documented…
rudolfdobias
  • 1,778
  • 3
  • 17
  • 40
25
votes
3 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; …
hcp
  • 3,268
  • 6
  • 26
  • 41
1
2 3
61 62