x509certificate2

Access X509 Certificate store with unmanaged C++

只谈情不闲聊 提交于 2019-12-02 04:28:38
问题 Does anyone know how I would do the equivalent of the below C# code using unmanaged C++ i.e. query a certificate from the X509 certificate store by thumbprint? var store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly); var allCerts = store.Certificates; foreach (var certificate in from X509Certificate2 certificate in allCerts where certificate.Thumbprint != null && certificate.Thumbprint.Equals(thumbprint, StringComparison.OrdinalIgnoreCase) select

Importing all certificates contained in a .p12 file

最后都变了- 提交于 2019-12-01 19:42:51
I have a .p12 file for my ASP.NET application to connect to a web service via HTTPS. I am trying to import the .p12 file into the Local Machine/My store. The .p12 file contains more than one certificate . One contains the private key and the other is the CA certificate to complete the chain. Currently I am using the `System.Security.Cryptography.X509Certificates.X509Certificate2 object's Import method to import this file into the store. Today I noticed that the CA certificate is not getting imported, only the main certificate containing the private key is getting imported using this method.

X509Certificate2.Verify() method always return false for the valid certificate

最后都变了- 提交于 2019-12-01 19:41:15
问题 I am using smart card for authentication. The SecurityTokenService (authentication service) is hosted on my machine only. The smart card has a valid certificate and it's root certificate is also installed in Local Computer store on my machine. When I use X509Certificate2.Verify method to validate the certificate in my service, it always return false . Can someone help me to understand why X509Certificate2.Verify() method always return false? Note: I used X509Chain and checked for all the

Importing all certificates contained in a .p12 file

我怕爱的太早我们不能终老 提交于 2019-12-01 19:01:29
问题 I have a .p12 file for my ASP.NET application to connect to a web service via HTTPS. I am trying to import the .p12 file into the Local Machine/My store. The .p12 file contains more than one certificate . One contains the private key and the other is the CA certificate to complete the chain. Currently I am using the `System.Security.Cryptography.X509Certificates.X509Certificate2 object's Import method to import this file into the store. Today I noticed that the CA certificate is not getting

X509Certificate2.Verify() method always return false for the valid certificate

*爱你&永不变心* 提交于 2019-12-01 17:56:20
I am using smart card for authentication. The SecurityTokenService (authentication service) is hosted on my machine only. The smart card has a valid certificate and it's root certificate is also installed in Local Computer store on my machine. When I use X509Certificate2.Verify method to validate the certificate in my service, it always return false . Can someone help me to understand why X509Certificate2.Verify() method always return false? Note: I used X509Chain and checked for all the flags ( X509VerificationFlags.AllFlags ). When I build the chanin, it returns true with ChainStatus as

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

耗尽温柔 提交于 2019-12-01 14:45:26
问题 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 content: "MIIF0QYJKoZI ........hvcNAQcCoIIFwjCCBb4CA0=" and file.PKCS7 is byte array which I downloaded from database . I've got the following exception when creating X509Certificate2 : Cannot find the requested object And the stack trace: "Cannot find

Using X509Certificate2 on Mono - loading with both public and private key?

不羁的心 提交于 2019-12-01 13:25:02
Right now, I try instantiating an X509Certificate2 like this: cert = new X509Certificate2(Resources.cred); Where Resources.cred is a byte[] representing a .pfx file. This works absolutely fine on Windows/.NET. However, running the same code under Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-4ubuntu1) (Mono on Ubuntu Server 14.04 LTS), I get the following exception: System.TypeInitializationException: An exception was thrown by the type initializer for <snipped irrelevant type name> ---> System.Security.Cryptography.CryptographicException: Unable to decode certificate. ---> System

Using X509Certificate2 on Mono - loading with both public and private key?

时光怂恿深爱的人放手 提交于 2019-12-01 11:30:52
问题 Right now, I try instantiating an X509Certificate2 like this: cert = new X509Certificate2(Resources.cred); Where Resources.cred is a byte[] representing a .pfx file. This works absolutely fine on Windows/.NET. However, running the same code under Mono JIT compiler version 3.2.8 (Debian 3.2.8+dfsg-4ubuntu1) (Mono on Ubuntu Server 14.04 LTS), I get the following exception: System.TypeInitializationException: An exception was thrown by the type initializer for <snipped irrelevant type name> --->

X509Certificate2 validation on web service

旧城冷巷雨未停 提交于 2019-12-01 10:59:48
I'm developing WCF web service that checks if a certificate in XML signature is valid. XML is signed with qualified and valid X509 certificate. While I am running service within Visual Studio development environment X509Certificate2.Verify() and X509Chain.Build() methods return TRUE. But when I publish my service under IIS these methods return FALSE. What I am doing wrong or what is missing? Here is my validation code: public static void VerifyXml(XmlDocument xDoc) { // Create a new SignedXml object and pass it // the XML document class. SignedXml signedXml = new SignedXml(xDoc); // Find the

How to get private key from PKCS#12 (.p12) file using C#

寵の児 提交于 2019-12-01 09:02:41
Im trying to sign some data using PKCS#12 certificate ,however i have problem with obtaining private key from PKCS#12 (.p12) file. public byte[] sign(string text) { string password = "1111"; X509Certificate2 cert = new X509Certificate2("c:\\certificate.p12",password); byte[] certData = cert.Export(X509ContentType.Pfx,password); X509Certificate2 newCert = new X509Certificate2(certData, password); RSACryptoServiceProvider crypt = (RSACryptoServiceProvider)newCert.PrivateKey; SHA1Managed sha1 = new SHA1Managed(); UnicodeEncoding encoding = new UnicodeEncoding(); byte[] data = encoding.GetBytes