Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to sign xml programatically using smart card
    text
    copied!<p>I have a problem signing xml programatically using smart card. When I pass pin code using popup dialog (when passPinAutomatically is set to false) it works, but when I pass pin code programatically I receive an error: A smart card was detected but is not the one required for the current operation. The smart card you are using may be missing required driver software or a required certificate.</p> <p>The code works on my local machine and on two other machines, but does not work on the production machine. The smart card reader is OMNIKEY 6121, the driver is up to date and everything seems to be fine. "Smart Card" and "Certificate Propagation" services are running. I have searched the internet for this issue but all solutions in the posts do not work for me. </p> <p>What could be the problem? I post a part of my source code below. You can see image of the error I receive. Please help, I am running out of time? Thank you.</p> <p><img src="https://i.stack.imgur.com/O6kW4.jpg" alt="enter image description here"></p> <pre><code>//X509Certificate2 certificate ... certificate object //string pin ... pinCode CspParameters csp = new CspParameters(1, "Microsoft Base Smart Card Crypto Provider"); csp.Flags = CspProviderFlags.UseDefaultKeyContainer | CspProviderFlags.UseExistingKey; SecureString pwd = new SecureString(); foreach (var c in pin) { pwd.AppendChar(c); } csp.KeyPassword = pwd; csp.KeyNumber = (int)KeyNumber.Signature; RSACryptoServiceProvider rsa; if (!passPinAutomatically) { rsa = (RSACryptoServiceProvider)certificate.PrivateKey; } else { rsa = new RSACryptoServiceProvider(csp); } KeyInfo keyInfo = new KeyInfo(); keyInfo.AddClause(new KeyInfoX509Data(certificate)); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml("&lt;signature&gt;&lt;/signature&gt;"); SignedXml signedXml = new SignedXml(xmlDocument); signedXml.KeyInfo = keyInfo; signedXml.SigningKey = rsa; Reference reference = new Reference(); reference.Uri = String.Empty; XmlDsigEnvelopedSignatureTransform transform = new XmlDsigEnvelopedSignatureTransform(); reference.AddTransform(transform); signedXml.AddReference(reference); signedXml.ComputeSignature(); string signedXmlText = signedXml.GetXml().InnerXml; Console.WriteLine(signedXml); Console.ReadLine(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload