Welcome to the ASP.NET Core feedback portal. We’re happy you’re here! If you have feedback on how to improve the ASP.NET Core, we’d love to hear it!

  • Check out the features or bugs others have reported and vote on your favorites. Feedback will be prioritized based on popularity.
  • If you have feedback that’s not listed yet, submit your own.

Thanks for joining our community and helping improve Syncfusion products!

1
Vote

I tried verifying digitally signed aadhar copy with code snippet provided by syncfusion but it is throwing an exception. Below is the code I tried with. Please help me if I am doing anything wrong.


using System;

using System.IO;

using System.Security.Cryptography.X509Certificates;

using Syncfusion.Pdf.Parsing;

using Syncfusion.Pdf.Security;

namespace VerifyAadhar

{

    class Program

    {

        static void Main(string[] args)

        {

            //System.IO.Stream f =

            //Load an existing PDF document.

            PdfLoadedDocument document = new PdfLoadedDocument(File.ReadAllBytes("../../../aadhar.pdf"));

            //Load PDF form.

            PdfLoadedForm form = document.Form;

            X509Store store = new X509Store("MY", StoreLocation.CurrentUser);

            store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

            X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;


            if (form != null)

            {

                foreach (PdfLoadedField field in form.Fields)

                {

                    if (field is PdfLoadedSignatureField)

                    {

                        PdfLoadedSignatureField signatureField = field as PdfLoadedSignatureField;


                        //Check whether the signature is signed.

                        if (signatureField.IsSigned)

                        {

                            PdfSignatureValidationResult result = signatureField.ValidateSignature(collection); //certificates


                            if (result.IsSignatureValid)

                                Console.WriteLine("Signature is valid");

                            else

                                Console.WriteLine("Signature is invalid");


                            //Retrieve the signature information.

                            Console.WriteLine("<<<<>>>>>>");

                            Console.WriteLine("Digitally Signed by: " + signatureField.Signature.Certificate.IssuerName);

                            Console.WriteLine("Valid From: " + signatureField.Signature.Certificate.ValidFrom);

                            Console.WriteLine("Valid To: " + signatureField.Signature.Certificate.ValidTo);

                            Console.WriteLine("Signature Algorithm : " + result.SignatureAlgorithm);

                            Console.WriteLine("Hash Algorithm : " + result.DigestAlgorithm);

                            Console.WriteLine("Cryptographics Standard : " + result.CryptographicStandard);

                            Console.Read();

                        }

                    }

                }

            }

        }

    }

}