How select certificate for signing a PDF

5/6/2013 7:55:33 PM
Gravatar
Total Posts 7

How select certificate for signing a PDF

Hi

I have created a simple test appplication for signing a PDF based on the FullTestNDigitSign example.

The PDF is signed with

pdfSigner.SignPDFFile([input file], selector, [output file])

Selector is defined as

Dim selector As ICertificateSelector

selector = New SimpleCertificateSelector()

In my case (SafeNet HSM) when running the pdfSigner.SignPDFFile command, a pop-up window opens where I can select the certificate I want  to use to sign the PDF.

My question: I have only one certificate in the slot. I want that this certififate is selected automatically, without user interaction. How can I do this?

Many thanks

5/7/2013 7:10:38 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: How select certificate for signing a PDF

You can see in the example folder. There is a file SimpleCertificateSelector that implements the interface ICertificateSelector.

Following such template you can write your own CertificateSelector following your requirements.

5/8/2013 7:57:23 PM
Gravatar
Total Posts 7

Re: How select certificate for signing a PDF

Thank you Ugo, I have overlooked the example file SimpleCertificateSelector.cs

Based on your example I created my own selector which returns the first certificate of the slot "slotname":

    Class SimpleCertificateSelector2
        Implements ICertificateSelector

        Public Function [Select](ByVal session As Session) As Certificate Implements ICertificateSelector.Select

            Dim template As New CryptokiCollection()
            template = New CryptokiCollection()
            template.Add(New ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_CERTIFICATE))
            template.Add(New ObjectAttribute(ObjectAttribute.CKA_CERTIFICATE_TYPE, NCryptoki.X509Certificate.CKC_X_509))
            template.Add(New ObjectAttribute(ObjectAttribute.CKA_LABEL, "slotname"))
            Dim objs As CryptokiCollection = session.Objects.Find(template, 1)
            If objs.Count = 0 Then Throw New Exception
            Return DirectCast(objs.Item(0), Certificate)

        End Function
    End Class

 

Thanks for the great support, great examples and great software smiley.