x509certificate2

ASP.NET MVC: “An internal error occurred.” when loading certificate bytes with X509Certificate2

微笑、不失礼 提交于 2019-12-06 08:23:54
问题 I have already spent a few hours to resolve this error. The weird thing is when I use this libraries independently, it works absolutely fine but when I integrate them with my ASP .NET MVC website, it start throwing the following exception. I have also used MachineKeySet flag based on suggestion here but still no luck. Could anyone please help me to get rid of this exception. Thanks. An internal error occurred. Description: An unhandled exception occurred during the execution of the current

Using X509Certificate Pfx for client certificate authentication creates too many temporary files in C:\\ProgramData\\Microsoft\\Crypto\\RSA\\MachineKeys

◇◆丶佛笑我妖孽 提交于 2019-12-06 07:16:09
We are using ClientCertificate authentication with HttpWebRequest. For the client certificate authentication we are creating the X509Certificate from Pfx file and attached to the outgoing HttpWebRequest. What we see is that after the request is created we are seeing to many temporary files in the folder : C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys As we make more request we see that the number of temporary files created in C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys folder is increasing continuously. We create the certificate from pfx file and then we set the key container. Expilicity

Convert a .PEM certificate to .PFX programmatically using OpenSSL

时光毁灭记忆、已成空白 提交于 2019-12-06 06:37:57
问题 I've got a .PEM file that I want to convert to a PKCS12 file (PFX), and I know I can easily accomplish this using the following openssl command: Create a PKCS#12 file: openssl pkcs12 -export -in file.pem -out file.p12 -name "My Certificate" Which is great, but I'd like to do this programmatically using OpenSSL calls. Unfortunately, documentation for OpenSSL is less than ideal. I've looked into doing this using other libraries: Using .NET: I can create a X509Certificate2 object from a PEM file

Converting a byte array to a X.509 certificate

爷,独闯天下 提交于 2019-12-06 06:35:03
问题 I'm trying to port a piece of Java code into .NET that takes a Base64 encoded string, converts it to a byte array, and then uses it to make a X.509 certificate to get the modulus & exponent for RSA encryption. This is the Java code I'm trying to convert: byte[] externalPublicKey = Base64.decode("base 64 encoded string"); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(externalPublicKey); Key publicKey = keyFactory.generatePublic

How can I encrypt, decrypt and sign using .pfx certificate?

白昼怎懂夜的黑 提交于 2019-12-06 00:34:32
I have a .pfx certificate file on my computer. I want to to encrypt a message with its public key, and then decrypt it with the private. Also I want to sign another message with its private key, and then check the signature. And I need to get the information about the sertificate the message was signed with from that message. How can I do it using System.Security.Cryptography? You can open the PFX in .NET, like the following: var path = <YOUR PFX FILE PATH>; var password = <YOUR PASSWORD>; var collection = new X509Certificate2Collection(); collection.Import(path, password, X509KeyStorageFlags

Problems generating a self-signed 1024-bit X509Certificate2 using the RSA AES provider

╄→гoц情女王★ 提交于 2019-12-05 22:24:29
I am trying to generate an X509Certificate2 object using the Microsoft AES Cryptographic Provider : CALG_AES_256 (0x00006610) 256 bit AES. This algorithm is supported by the Microsoft AES Cryptographic Provider. My problem is that my call to CryptGenKey(providerContext, 0x6610, 0x4000001, out cryptKey) fails with the following error: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll Additional information: Invalid flags specified. (Exception from HRESULT: 0x80090009) The flags I am using are (1024 << 16) | 1) . Unless I am mistaken, should

Create a X509Certificate2 from RSACryptoServiceProvider fails with Cannot find the requested object

不羁的心 提交于 2019-12-05 21:58:13
问题 Sample code: CspParameters cspParameters = new CspParameters(); cspParameters.ProviderType = 1; // PROV_RSA_FULL // Create the crypto service provider, generating a new // key. mRsaCSP = new RSACryptoServiceProvider(mDefaultKeyLength, cspParameters); mRsaCSP.PersistKeyInCsp = true; RSAParameters privateKey = mRsaCSP.ExportParameters(true); byte[] rsaBytes = mRsaCSP.ExportCspBlob(true); try { X509Certificate2 cert = new X509Certificate2(rsaBytes); mKeyDataPfx = Convert.ToBase64String(cert

Prevent file creation when X509Certificate2 is created?

雨燕双飞 提交于 2019-12-05 04:18:50
We create a X509Certificate2 object in our ASP.NET app to make periodic outgoing connections. Every time one of these certificates is created a new file is created in: C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys That folder now has 4 million files that never get cleaned up. I've tried removing the Persist flag new X509Certificate2(certBytes, p12Pwd, X509KeyStorageFlags.MachineKeySet); //no X509KeyStorageFlags.PersistKeySet but that doesn't help -- still get the 2Kb file on every call. I got my hopes up when I saw this answer , but this is a 2008 R2 server, and the temp files are not 0

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

我只是一个虾纸丫 提交于 2019-12-05 00:04:53
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 collection = new X509Certificate2Collection(); collection.Import("C:\\SomePath\\MyCertificate.pfx", "MyPassword", X509KeyStorageFlags.PersistKeySet); var cert = collection[0]; ServicePointManager.SecurityProtocol = ...; ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true; HttpClientHandler handler =

ASP.NET MVC: “An internal error occurred.” when loading certificate bytes with X509Certificate2

依然范特西╮ 提交于 2019-12-04 14:14:41
I have already spent a few hours to resolve this error. The weird thing is when I use this libraries independently, it works absolutely fine but when I integrate them with my ASP .NET MVC website, it start throwing the following exception. I have also used MachineKeySet flag based on suggestion here but still no luck. Could anyone please help me to get rid of this exception. Thanks. An internal error occurred. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated