Doc.save overflow error in Syncfusion.Pdf.Base.dll

Hello ,
I was trying to sign a pdf file using a certificate from a usb token.(Aladin usb etoken pro 72)
I used the following code (copied from documentation ) :

"namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {// Creates a new document
            PdfDocument doc = new PdfDocument();
            //Creates a new page and adds it as the last page of the document
            PdfPage page = doc.Pages.Add();
            //Create new PDF certificate instance.
            PdfCertificate pdfCert = PdfCertificate.FindBySubject(0, "DARABAN GABRIEL");              
            //Create new PDF signature instance.
            PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
            signature.Bounds = new System.Drawing.RectangleF(new System.Drawing.PointF(5, 5), new System.Drawing.SizeF(100, 200));
            doc.Save("SignedPdfSample.pdf");
            doc.Close(true);
        }
    }
}"

Everything is ok until the line doc.Save where it raise an overflow error :
Exception thrown: 'System.OverflowException' in Syncfusion.Pdf.Base.dll
An unhandled exception of type 'System.OverflowException' occurred in Syncfusion.Pdf.Base.dll
Arithmetic operation resulted in an overflow.
My guess is that the problem is caused by the certificate i am using .
I use a certificate issued by DIGISIGN  
C=RO,O=DigiSign S.A.,2.5.4.97=VATRO-17544945,OU=DigiSign Certification Services,CN=DigiSign Qualified CA Class 3 2017
PKIX QCSyntax-v2 [1.3.6.1.5.5.7.11.2]
ETSI QC Compliance [0.4.0.1862.1.1]
ETSI Transaction Value Limit [0.4.0.1862.1.2]
ETSI Retention Period [0.4.0.1862.1.3]
ETSI Secure Signature Creation Device [0.4.0.1862.1.4]
OID [0.4.0.1862.1.6]
OID [0.4.0.1862.1.5]

Is there any way to resolve the error ?
Thank you

7 Replies

KC Karthikeyan Chandrasekar Syncfusion Team July 20, 2018 12:40 PM UTC

Hi Gabriel, 
At present, we do have support only to sign the certificate with private key. Please confirm if your certificate installed in the store have the private key. Also it will be helpful if you could share us the certificate and the complete stack trace for further validation. You may also create a Direct-Trac incident for sharing us the requested details. 

Regards, 
Karthikeyan 



GD Gabriel Daraban July 20, 2018 04:34 PM UTC

Hello  KarthikeyanC,

Sorry I didn't knew about the restriction regarding the use of certificates including private key.
As I know it is my case , private key is being stored  on USB token.
Case is solved :)  for know.
Thank you 
 
PS: here is full list of errors after I put a try-catch branch  into program  :
'ConsoleApp2.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ConsoleApp2.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Users\lenovo\source\repos\ConsoleApp2\ConsoleApp2\bin\Debug\ConsoleApp2.exe'. Symbols loaded.
'ConsoleApp2.exe' (CLR v4.0.30319: ConsoleApp2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Syncfusion.Pdf.Base\v4.0_16.2460.0.41__3d67ed1f87d44c89\Syncfusion.Pdf.Base.dll'. Module was built without symbols.
'ConsoleApp2.exe' (CLR v4.0.30319: ConsoleApp2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ConsoleApp2.exe' (CLR v4.0.30319: ConsoleApp2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ConsoleApp2.exe' (CLR v4.0.30319: ConsoleApp2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ConsoleApp2.exe' (CLR v4.0.30319: ConsoleApp2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Syncfusion.Compression.Base\v4.0_16.2460.0.41__3d67ed1f87d44c89\Syncfusion.Compression.Base.dll'. Module was built without symbols.
'ConsoleApp2.exe' (CLR v4.0.30319: ConsoleApp2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Security\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Security.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Exception thrown: 'System.OverflowException' in Syncfusion.Pdf.Base.dll
'ConsoleApp2.exe' (CLR v4.0.30319: ConsoleApp2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ConsoleApp2.exe' (CLR v4.0.30319: ConsoleApp2.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Arithmetic operation resulted in an overflow.
   at Syncfusion.Pdf.Security.PdfSignatureDictionary.DocumentSaved(Object sender, DocumentSavedEventArgs e)
   at Syncfusion.Pdf.PdfDocumentBase.OnDocumentSaved(DocumentSavedEventArgs args)
   at Syncfusion.Pdf.PdfDocument.Save(Stream stream)
   at Syncfusion.Pdf.PdfDocumentBase.Save(String filename)
   at ConsoleApp2.Program.Main(String[] args) in C:\Users\lenovo\source\repos\ConsoleApp2\ConsoleApp2\Program.cs:line 29

The program '[11204] ConsoleApp2.exe' has exited with code 0 (0x0).




KC Karthikeyan Chandrasekar Syncfusion Team July 23, 2018 04:40 AM UTC

Hi Gabriel, 
Thank you for your update, please let us know if you need any further assistance. 

Regards, 
Karthikeyan 



IM Ido Millet November 5, 2018 07:51 PM UTC

Hi Gabriel,
I'm running into the same exact issue using an AATL digital certificate signature token from Globalsign.
Can you describe how you resolved the problem?


GD Gabriel Daraban November 5, 2018 10:34 PM UTC

Hello Ido ,

Unfortunately I couldn't found  a good method  to sign pdf's using c# and certificates stored on usb tokens.
Since it is  a personal project i didn't continued with it due to lack of time.
If you find something viable please share.



KC Karthikeyan Chandrasekar Syncfusion Team November 7, 2018 12:41 PM UTC

Hi Gabriel,  
Internally we are using Microsoft API “X509Certificate2” to sign the PDF document, this API supports the version 3 of the X509 Certificates. Can you please ensure that the private key is placed along with the certificate, please export your certificate to “.pfx” with private key as steps provided in the following link and share it with us, it will help us to investigate further in this issue.  

Regards,  
Karthikeyan   



GD Gabriel Daraban November 7, 2018 02:07 PM UTC

Hello Karthikeyan ,

Unfortunately this is not a solution because of following : 
1.) Private key is not exportable in my case .I attached a capture of the screen

2.)Even if it would have been exportable it is not a solution that could be deployed to other persons.
Usb tokens are used to keep safe the private key ,exporting private key to  .pfx file is not safe enough to some people.

I have understood from your first post that Syncfusion.Pdf.Base.Dll needs that private key to be exported to a pfx file so that is why i didn't continue  with it.
Luckily i don't have any deadlines regarding this problem . 


Attachment: notexportable_424bca3d.7z

Loader.
Up arrow icon