Re: Provider's public key is invalid

On Sep 11, 5:23 am, Paulo Fernandes
<PauloFernan...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
"Del Brocco Andrea" wrote:
I'm try to sign a file using smart card.
I'm using visual studio 2008

 public static byte[] SignMsg(Byte[] msg, X509Certificate2
bool detached)
            //  Place message in a ContentInfo object.
            //  This is required to build a SignedCms object.
            ContentInfo contentInfo = new ContentInfo(msg);

            //  Instantiate SignedCms object with the ContentInfo
            //  Has default SubjectIdentifierType
            SignedCms signedCms = new SignedCms(contentInfo,

            //  Formulate a CmsSigner object for the signer.
            CmsSigner cmsSigner = new CmsSigner(signerCert);

            // Include the following line if the top certificate in
            // smartcard is not in the trusted list.
            cmsSigner.IncludeOption = X509IncludeOption.EndCertOnly;

            //  Sign the CMS/PKCS #7 message. The second argument is
            //  needed to ask for the pin.
            signedCms.ComputeSignature(cmsSigner, false);

            //  Encode the CMS/PKCS #7 message.
            return signedCms.Encode();

I have installed the certificate in the storage, when i encrypt it
the pin and sign succesfully.

In windows 2003 with the same smart card and different readers i'm be
able succesfully to sign a file and produce a pm7 sucessfully, or
a PDF.

The same code with same card throw "Provider's public key is invalid"
exception in vista, i've tryed 3 different pc with vista and
smart card, with 2003 works fine in vista no.

I'm trying to investigate ACL in certificate store but unsuccesfully.

Andrea Del Brocco

I'm using the exactly same code, evrything works fine exactly 3 times.
Then I get the same error as above: "Provider's public key is invalid"
If I start another process with or without ending the first one, I get 3
more sucessfull signing "sessions".
When I exit the application I get an strage windows Null Referenced Memory
error. Actualiy I get an access violation error exactly prior to "Providers'
public key is invalid" error.

This only happens if I use a smartcard certificate. If I use an installed
certificate I get no error. And if I use the smartcard certificate in word I
can use the certificate to sign the document any times I want to.

I believe that something is not being released but can't figure it out.

Does anybody has the same error? Or better, does anybody know how to get it




I am facing the same problem. I am using almost the same code and
working in Visual Studio 2005 so targeting .net framework 2.0. My code
works fine on Windows XP with most of the smart cards and also on
Vista but throws this error with a particular smart card from a vendor
named "Bit4id". Could it be a problem on the CSP side implemented by
the vendor or is it an issue with the .net framework?

Any workaround as well?

Hashim Saleem