The Contents field is empty or missing. The digital signature is compromised

We are using APSOSE pdf to generate pdf along with digital signature. We are getting inconsistent error while generating pdf with digital signature. This was working fine till last week. But not sure after new version released on 15th Oct, Digital signature stops functioning consistently. Below is the error description.

Error Desc - The Contents field is empty or missing. The digital signature is compromised
Stack trace - “at Aspose.Pdf.Forms.Signature.#=zQzLrbK_N8Ahc5pMnWcRVGKU=(#=zCSGqRHoKA8soenH3p5ChG11Uz66biA5jzQ== #=zFCA7FbA=, #=zkcDp5IS0prWj166X9$W1gb6402u5 #=znc1dJts=) at Aspose.Pdf.Forms.Signature…ctor(#=zCSGqRHoKA8soenH3p5ChG11Uz66biA5jzQ== #=zFCA7FbA=, #=zkcDp5IS0prWj166X9$W1gb6402u5 #=znc1dJts=) at Aspose.Pdf.Forms.PKCS7…ctor(#=zCSGqRHoKA8soenH3p5ChG11Uz66biA5jzQ== #=zFCA7FbA=, #=zkcDp5IS0prWj166X9$W1gb6402u5 #=znc1dJts=) at Aspose.Pdf.Forms.SignatureField…ctor(#=zjIvfumiDMs7BZw2lAlZKJbGoZhq24lOBWw== #=zB6uX1f4=, Document #=znc1dJts=) at Aspose.Pdf.Forms.Field.#=zvxSR1Yw=(#=zjIvfumiDMs7BZw2lAlZKJbGoZhq24lOBWw== #=zdJK9Fy8=, Document #=znc1dJts=) at Aspose.Pdf.Forms.Form.#=zN69MPUI=.get_Current() at Aspose.Pdf.Forms.Form.#=zSnfudjJ$S2w$6GQowOStPS8=(String #=zev04klS3x6pjWeUBNw==, #=zOxfbL$$hmenCu4RzcSG_dkaCtPjsi0j5Vw== #=zBntGMlA=, ICollection1 #=z$nHgBBc=) at Aspose.Pdf.Forms.Form.#=zRi7UZfU=(String #=z$qUIzag=) at Aspose.Pdf.Facades.Form.FillField(String fieldName, String fieldValue) at EY.TAX.eTFV.Common.PDFHandler.CreatePDF(IDictionary2 fields, Stream templatefile, Stream licstream, Stream PFXStream, Boolean isSign, IDictionary`2 signvalues, String webRootPath) in /src/EY.TAX.eTFV.Common/PDFHandler.cs:line 30 at EY.TAX.TFV.Services.Concrete.CaseService.UploadCaseForm(Int64 caseId, String clientName, String dbName, Boolean Issigned, String webRootPath) in /src/EY.TAX.TFV.Services/Concrete/CaseService.cs:line 67 at EY.TAX.eTFV.WebApp.Controllers.CustomerController.PDFForm(Int64 caseid, Boolean isUpload, Boolean Issigned) in /src/EY.TAX.eTFV.WebApp/Controllers/CustomerController.cs:line 136 at lambda_method(Closure , Object , Object[] ) at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)”

We have Aspose licence and this issue is super critical.

Any help on this issue will be highly appreciated.

@david_dellobuono_ey_com

Thank you for contacting support.

Would you please share a sample application containing SSCCE code along with source file, if any, so that we may try to reproduce and investigate it in our environment.

Hi Team

Here is the code which we implemented for digital signature.

====================================================================

public static MemoryStream DoDigitalSign(Stream PFXStream, Stream templatefile, IDictionary<string, string> signvalues = null, string webRootPath = null)
{
string pfxFile = webRootPath + @"/pfx/eTFV.PDF.pfx";
PKCS7 signature = new PKCS7(pfxFile, “#######”);
System.Drawing.Bitmap bmp = CreateBitmapImage_Try6(“Electronically Signed By " + signvalues[“FirstName”]+” "+ signvalues[“Surname”], DateTime.Now.ToString(“dd MMMM yyyy, HH:MM:ss”));
MemoryStream msIn = new MemoryStream();
bmp.Save(msIn, System.Drawing.Imaging.ImageFormat.Png);
PdfFileSignature pdfSign = new PdfFileSignature();
pdfSign.BindPdf(templatefile);

        int x = 0, y = 0, pageNumber = 0;
        if (signvalues["FormName"] == "W-8BEN")
        {
            x = 140;
            y = 80;
            pageNumber = 1;
        }
        if (signvalues["FormName"] == "CRS Self-Certification")
        {
            //x = 150;
            //y = 475;
            //pageNumber = 4;
            x = 120;
            y = 150;
            pageNumber = 1;
        }

        System.Drawing.Rectangle rect = new System.Drawing.Rectangle(x, y, bmp.Width, bmp.Height - 5);
        //System.Drawing.Rectangle rect = new System.Drawing.Rectangle(Convert.ToInt32(signvalues["SignXAxis"]), Convert.ToInt32(signvalues["SignYAxis"]), bmp.Width, bmp.Height - 5);
        signature.ShowProperties = false;
        TimestampSettings timestampSettings = new TimestampSettings("http://timestamp.digicert.com", null);
        signature.TimestampSettings = timestampSettings;
        pdfSign.SignatureAppearanceStream = msIn;
        MemoryStream stream = new MemoryStream();
        pdfSign.Sign(pageNumber, null, null, null, true, rect, signature);
        pdfSign.Save(stream);
        //stream.Seek(0, SeekOrigin.Begin);
        msIn.Close();
        return stream;
    }

====================================================================

Please consider this as a high priority.

@david_dellobuono_ey_com

Could you kindly share the sample source files which were used in the shared code snippet so that we can test the scenario accordingly.

Hi Asad,

Do you want me to share .cs file. How can I attached it.

@david_dellobuono_ey_com

We have requested for the .pfx and .pdf files which were being used in your code snippet. You may please share them by adding them to archive in ZIP format so that we may further proceed to assist you.

Please refer attached sample .pfx file and w8ben pdf files.

userid and pwd of .pfx file is mentioned in attached txt file.
fw8ben.pdf (61.1 KB)
eTFV_DIgiSignature.zip (51.7 KB)

Hi Team,

Can you please provide more updates on this issue. Please let me know if you need any more details to simulate this issue on your side.

@david_dellobuono_ey_com

Thank you for sharing requested data.

We have tried to reproduce the issue but the signatures are valid. We have attached generated PDF document for your kind reference. Would you please elaborate with screenshots if you notice any problem. Test_19.10.pdf