Signature Verification in C++

Use PdfFileSignature for this task. The examples below retain the original C++ code and API Reference steps.

Verify PDF signature

Print the first signature’s verification result and whether it covers the whole document.

  1. Create PdfFileSignature.
  2. Bind the PDF input with Facade::BindPdf().
  3. Read signature identifiers with PdfFileSignature::GetSignatureNames().
  4. Verify the signature with PdfFileSignature::VerifySignature().
  5. Check document coverage with PdfFileSignature::CoversWholeDocument().
  6. Print the results or diagnostic messages shown in the example.
#include <Aspose.PDF.Cpp/Facades/PdfFileSignature.h>
#include <Aspose.PDF.Cpp/Facades/SignatureName.h>
#include <iostream>
#include <system/collections/ilist.h>
#include <system/string.h>

namespace Facades::Examples::PDF_FileSignature
{
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Facades;

void VerifyPdfSignature(String inputFile)
{
    auto pdfSignature = MakeObject<PdfFileSignature>();
    pdfSignature->BindPdf(inputFile);
    auto signatureName = pdfSignature->GetSignatureNames()->idx_get(0);
    std::cout << "Signature '" << signatureName->ToString()
              << "' is valid: " << pdfSignature->VerifySignature(signatureName) << std::endl;
    std::cout << "Signature covers whole document: " << pdfSignature->CoversWholeDocument(signatureName) << std::endl;
}
} // namespace Facades::Examples::PDF_FileSignature