Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Sun Jan 22, 2017 12:27 pm

Hello,

I'm evaluating Spire.PDF to sign digitaly PDFs using a Smart Card.

When the Card is inserted in the reader, the Card software copies the Certificate to the certificate store.
Then i load the certificate from the store and when i save the PDF it asks for the PIN as expected.
The problem is that it asks for the PIN 4 times before saving the document...

Code: Select all
private void applySignature()
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
           
            doc.LoadFromFile(@"C:\Temp\Autenticacao.Gov_Manual_de_Integracao_v1.4.1.pdf");

            // Create one page
            PdfPageBase page = doc.Pages[0]; //section.Pages.Add();

            X509Store store = new X509Store("My");

            store.Open(OpenFlags.ReadOnly);

            PdfCertificate cert = new PdfCertificate(store.Certificates[0].GetRawCertData());

            foreach (var item in store.Certificates)
            {
                if (item.SubjectName.Name.Contains("my name extracted from the card in other method") && item.IssuerName.Name.Contains("EC de Assinatura Digital Qualificada do Cartão de Cidadão"))
                {
                    cert = new PdfCertificate(item.GetRawCertData());
                    break;
                }
            }
           
            PdfSignature sig = new PdfSignature(doc, page, cert, "demo");

            sig.Bounds = new RectangleF(new PointF(280, 600), new SizeF(260, 90));
            sig.IsTag = true;

            sig.Certificated = false;
            sig.DocumentPermissions = PdfCertificationFlags.ForbidChanges;
            sig.Date = DateTime.Now;
           
            //Save doc file.
            doc.SaveToFile(@"C:\Temp\Signature.pdf");

            doc.Close();

            //Launching the Pdf file.
            System.Diagnostics.Process.Start(@"C:\Temp\Signature.pdf");
        }


Is this normal?
I tried already the SecureBlackbox DLLs with this logic and it only ask the PIN once.

Thanks for your support

Moerbius
 
Posts: 3
Joined: Sat Jan 21, 2017 12:39 pm

Mon Jan 23, 2017 9:03 am

Dear Moerbius,

Thanks for your inquiry.
Sorry that we don't have the smart card device on our side, I am afraid that we might not locate where it asked for the PIN, so could you please help to check if the marked place will ask for PIN or other places? Then we will do the investigation accordingly.
Code: Select all
        PdfDocument doc = new PdfDocument();
        doc.LoadFromFile(@"C:\Temp\Autenticacao.Gov_Manual_de_Integracao_v1.4.1.pdf");
        PdfPageBase page = doc.Pages[0];
        X509Store store = new X509Store("My");
        store.Open(OpenFlags.ReadOnly); //this run     
        PdfCertificate cert = null;
        foreach (var item in store.Certificates)
        {
            if (item.SubjectName.Name.Contains("my name extracted from the card in other method") && item.IssuerName.Name.Contains("EC de Assinatura Digital Qualificada do Cart?o de Cidad?o"))
            {
                cert = new PdfCertificate(item.GetRawCertData());//this run
                break;
            }
        }
        PdfSignature sig = new PdfSignature(doc, page, cert, "demo");//this run   
        sig.Bounds = new RectangleF(new PointF(280, 600), new SizeF(260, 90));
        sig.IsTag = true;
        sig.Certificated = false;
        sig.DocumentPermissions = PdfCertificationFlags.ForbidChanges;
        sig.Date = DateTime.Now;
        doc.SaveToFile(@"C:\Temp\Signature.pdf");


Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Jan 23, 2017 5:37 pm

Hello Jiang,

It asks for the PIN on SaveToFile method. I've also tried SaveToStream but it has the same behaviour.

Best regards,
Moerbius

Moerbius
 
Posts: 3
Joined: Sat Jan 21, 2017 12:39 pm

Tue Jan 24, 2017 2:02 am

Dear Moerbius,

Thanks for your response.
What the version you were using ? Is the latest Spire.PDF Pack(Hot Fix) Version:3.8.158 ? Did it has same issue ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Jan 25, 2017 2:39 am

Hello Jiang,

Yes, it does the same with the hotfix.

Best regards

Moerbius
 
Posts: 3
Joined: Sat Jan 21, 2017 12:39 pm

Wed Jan 25, 2017 2:42 am

Dear Moerbius,

Many thanks for your information.
We are investigating this issue, we will notify you as soon as there is any news.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Jan 08, 2021 2:40 am

Hello,

Sorry for the long silence.
Glad to inform that we just released Spire.PDF 7.1.0 which made some adjustments for PIN entering issue. Based on the PDF specification, now it needs to enter two times, one time is to check the length of the signature content, one time is to sign. Meanwhile, please refer to the attached custom class file (CustomPKCS7SignatureFormatter.cs), if adding the signature length parameter like the attached screenshot (CustomSignatureSetting.png), it will only need to enter one time, otherwise it needs to enter two times by default.

Please download the latest version from the following links and refer to the following code to test. If there is any question, just feel free to write back.
Website link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link: https://www.nuget.org/packages/Spire.PDF/

Code: Select all
……
//create CustomPKCS7SignatureFormatter
CustomPKCS7SignatureFormatter customPKCS7SignatureFormatter = new CustomPKCS7SignatureFormatter(cert);
PdfSignature signature = new PdfSignature(doc, doc.Pages[0], customPKCS7SignatureFormatter, "signature0");
signature.Bounds = new RectangleF(new PointF(90, 550), new SizeF(270, 90));
signature.GraphicsMode = GraphicMode.SignDetail;
signature.NameLabel = "Signer:";
signature.Name = "Test";
signature.Reason = "The certificate of this document";
signature.DistinguishedNameLabel = "DN: ";
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
signature.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15);
signature.SignImageLayout = SignImageLayout.None;
//Save pdf file.
doc.SaveToFile(@"output.pdf", Spire.Pdf.FileFormat.PDF);


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF