.NET Class for handling X.509 Certificates
Questions tagged [x509certificate2]
922 questions
10
votes
2 answers
X509Chain.Build() method explanation
I want to validate chain of certificates, I get a X509Certificate2 collection and have to validate if all the certificates build one chain.
Usually, in order to verify the certificates chain I should take the digital signature from the leaf…

RRR
- 3,937
- 13
- 51
- 75
10
votes
2 answers
Client certificate with HttpClient in c#
Want to send data with client certificate (.p12 or .pfx) from Windows application to Server machine, Windows application developed in .Net Framework 4.6, OS is windows 10.
When hit from postman with client certificate (.p12 or .pfx) [Loaded in…

Somnath Kadam
- 6,051
- 6
- 21
- 37
10
votes
2 answers
Why does X509Certificate2 sometimes fail to create from a blob?
I have an ASP.NET web service which is receiving a byte array representing the contents of a .pfx file containing an X.509 certificate. The server-side code is using the System.Security.Cryptography.X509Certificate2 constructor to load the…

jlew
- 10,491
- 1
- 35
- 58
10
votes
2 answers
Can't read certificate when running in Linux Docker container - works on Windows
I'm trying to read information from an SSL certificate (in this case I've saved a copy of StackOverflow's via Chrome) but for some reason the moment I build it and run it from within a Linux Docker container, it fails to output anything.
On Windows…

ProgrammingLlama
- 36,677
- 7
- 67
- 86
10
votes
4 answers
X509Certificate2 Error - System cannot find the file specified
The associated code, works well in an independent console application, whereas errors out, while trying to make it work, within an NSB architecture. I have tried to test the same within the worker, and also independently within a test console app.…

Rakesh Kumar
- 307
- 1
- 2
- 10
10
votes
1 answer
Powershell "X509Certificate2Collection" Exception calling "Import" with "3" argument(s): "Cannot find the requested object
I have the below piece of code to download cert from Azure Key Vault.
$secretName = "TestCert"
$kvSecret = Get-AzureKeyVaultSecret -VaultName $vaultName -Name $certificateName
$kvSecretBytes =…

user1335978
- 193
- 4
- 13
10
votes
1 answer
C# - Export .pfx certificate and import it later as a file
I basically need to export a .pfx certificate as a Base64string, store it in a database and recover it later, converting from Base64string.
What I'm using at the moment is the X509Certificate2 class like the following:
To convert it and store in DB…

Wesley Kalatai
- 103
- 2
- 5
10
votes
1 answer
Offline revocation mode
My question is similar to this question.
I am trying to check revocation list only using the local CRL.
I am using X509Chain.Build() with the following parameters:
var chainMachine = new X509Chain(true);
…

user844541
- 2,868
- 5
- 32
- 60
10
votes
4 answers
Why do I get an Access Denied error when creating an X509Certificate2 object?
We have some unit tests which have PFX certificates embedded in them. These certificates are read during test execution and turned into X509Certificate2 objects. Unfortunately, when run as an unprivileged user, we get Access Denied…

Aaron Jensen
- 25,861
- 15
- 82
- 91
9
votes
3 answers
Can't read CurrentUser certificates from X509Store
I'm developing ASP.NET 4.0 web application, and I want to read the current user certificates from X509Store. Reading the LocalMachine certificates works fine, but if I set the StoreLocation to CurrentUser, it gives me an empty collection.
The…

Masinov
- 233
- 4
- 11
9
votes
4 answers
PrivateKey threw an exception of type System.Security.Cryptography.CryptographicException
I'm trying to use self-signed certificate using the following code:
X509Certificate2 cert = ToCertificate("CN=localhost");
public static X509Certificate2 ToCertificate(this string subjectName,
…

Anas Tina
- 329
- 1
- 2
- 14
9
votes
2 answers
How to make priv key in certificate not exportable C#
So below you'll find my code that creates a self signed certificate with the private key in there. It's stored in the user store. Now when I use the mmc tool I can just export the private key from the certificate? I thought that was a flag you had…

Spyral
- 760
- 1
- 12
- 33
8
votes
1 answer
Create a X509Certificate2 from RSACryptoServiceProvider fails with Cannot find the requested object
Sample code:
CspParameters cspParameters = new CspParameters();
cspParameters.ProviderType = 1; // PROV_RSA_FULL
// Create the crypto service provider, generating a new
// key.
mRsaCSP = new…

arunpereira
- 582
- 5
- 13
8
votes
2 answers
C# convert certificate string into X509 certificate
I am receiving a string and want to convert that into a certificate using C#. I tried following code and got "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character…

SharpCoder
- 18,279
- 43
- 153
- 249
8
votes
1 answer
.NET Core 2.2, Azure Web API new X509Certificate2 "The system cannot find the file specified" and "access denied"
My Azure Web API loads a certificate stored as a secret in Key Vault and then attempts to create a new certificate from a byte array. Running locally everything works, but, when deployed to Azure we get Access Denied or The system cannot find the…

user2503078
- 737
- 1
- 8
- 24