My client have a smart card in his computer and when he access my application through browser I can access the X509Certificate2 class of the connected smart card. The problem is that I need to sign a XML with his information and the privatekey, RSA private key and DSA private key is null in the X509 class. I have a WPF program that show the privatekey but when I need to access in browser through my .Net Core app don't work.
I'm using IIS by the way.
I'm getting the information of his card on Program.cs in the service:
services.AddAuthentication(CertificateAuthenticationDefaults.AuthenticationScheme).AddCertificate(options => {
options.AllowedCertificateTypes = CertificateTypes.All;
options.Events = new CertificateAuthenticationEvents {
OnCertificateValidated = context => {
context.HttpContext.Connection.ClientCertificate = context.ClientCertificate; // <- that line
};
});
The context.ClientCertificate don't has a privatekey and when I call the ComputeSignature method in SignedXml class I got the error CryptographicException "Signing key is not loaded".
How I get the privatekey of the smartcard or how I proceed to get the SignedXml.ComputeSignature working?
Sorry for the bad english.