Martin
Martin

Reputation: 134

How to gain access to private key of PKI certificate via Smart Card reader without PIN prompt?

I need to gain access to private key of PKI certificate which is stored in a card. I have access to it via Smart Card reader. Whenever I try to use private key, at first time I always have to enter PIN number into PIN prompt.

Is it possible to enter PIN programmatically and use private key without PIN prompt? I need to create WCF service that will sign the input data using PKI certificate and take them back signed to user.

In that way I currently try to sign data using PKI certificate using C#:

var cmsSigner = new CmsSigner(x509certificate2); // certificate fetched from store
var contentInfo = new ContentInfo(dataToSign);
var signedCms = new SignedCms(contentInfo, true);
signedCms.ComputeSignature(cmsSigner, false);

PIN prompt always opens at the first ComputeSignature method call. How can I pass PIN to gain access to private key directly and avoid entering PIN manually via prompt?

Upvotes: 2

Views: 3062

Answers (1)

Maarten Bodewes
Maarten Bodewes

Reputation: 94048

It comes down to two situations:

  1. the hardware CSP (crypto service provider) keeps to the Microsoft defined API and implements CspParameters correctly;
  2. the hardware CSP itself generates a pop up for the PIN when a private key operation is required.

In the first case you should read How to: Access Hardware Encryption Devices and then try to pass a KeyPassword to the CSP.

In the latter case it probably amounts to contacting the company that created the CSP and ask which options are available. Fortunately this option is usually not implemented anymore.

Upvotes: 1

Related Questions