x509certificate2

X509 certificate not loading private key file on server

时间秒杀一切 提交于 2019-11-28 16:59:14
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, "notasecret", X509KeyStorageFlags.Exportable); var Provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, Cert) { ServiceAccountId = ServiceAccountUser, Scope = ApiUrl + "analytics.readonly" }; var Auth = new OAuth2Authenticator<AssertionFlowClient>(Provider, AssertionFlowClient.GetState); Service = new AnalyticsService(Auth); } PrivateKeyPath

Different S/MIME signature between OpenSSL and C#

元气小坏坏 提交于 2019-11-28 14:03:27
I'm trying to use an OpenSSL code in my .Net program. Here's the code: openssl pkcs12 -in "My PassKit Cert.p12" -clcerts -nokeys -out certificate.pem openssl pkcs12 -in "My PassKit Cert.p12" -nocerts -out key.pem smime -binary -sign -signer certificate.pem -inkey key.pem -in manifest.json -out signature -outform DER I tried to use .Net OpenSSL, but I absolutely have no idea how to use it, and I couldn't find a good documentation for it. I decided to use .Net to perform the same sign process, here's the code: var dataToSign = System.IO.File.ReadAllBytes(filePathToSign); ContentInfo contentInfo

What is the rationale for all the different X509KeyStorageFlags?

懵懂的女人 提交于 2019-11-28 11:20:35
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 you can land in situations with all sorts of weird bugs such as: unexpectedly can't tell NETSH.exe or ASP.net to use a certain SSL certificate [by its thumbprint], even though you have that cert in your machine store unexpectedly you can export the cert data but it gets exported without the private key using .Export() unexpectedly your unit tests

Exporting a Certificate as BASE-64 encoded .cer

别说谁变了你拦得住时间么 提交于 2019-11-28 08:03:13
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 data...I think it is...not readable. X509Certificate2 cert = new X509Certificate2("c:\\myCert.pfx", "test", X509KeyStorageFlags.Exportable); File.WriteAllBytes("c:\\testcer.cer", cert.Export(X509ContentType.Cert)); I tried removing the 'X509KeyStorageFlags.Exportable" but that doesn't work. Am I missing something? Edit - I tried File.WriteAllText("c:\

Site in Azure Websites fails processing of X509Certificate2

↘锁芯ラ 提交于 2019-11-28 06:45:54
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[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) at

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

余生长醉 提交于 2019-11-28 04:53:48
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 lost trying to troubleshoot because _LoadCertFromBlob is marked [MethodImpl(MethodImplOptions.InternalCall)] . System.Security.Cryptography.CryptographicException: The system cannot find the file specified. at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr) at System.Security.Cryptography.X509Certificates

Exporting X.509 certificate WITHOUT private key

人盡茶涼 提交于 2019-11-28 02:59:38
问题 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

Generating self-signed certificate without external libraries

对着背影说爱祢 提交于 2019-11-28 02:00:05
问题 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

Export private/public keys from X509 certificate to PEM

情到浓时终转凉″ 提交于 2019-11-28 01:56:10
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 anywhere.. Let's have an X509Certificate2 var cert = new X509Certificate2(someBytes, pass); var privateKey = cert.GetRSAPrivateKey(); var publicKey = cert.GetRSAPublicKey(); // assume everything is fine so far And now I need to export the keys as two separate PEM keys. I already tried PemWriter in BouncyCastle but the types are not compatibile with System

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

丶灬走出姿态 提交于 2019-11-27 19:46:42
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 CA Organization certificate CA Organization 2 certificate CA My certificate The code I use looks like this: cert = new X509Certificate2(pathToCert, password); if (cert != null) { var store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadWrite); if (!store.Certificates.Contains(cert)) { store.Add(cert); } } This code does