コード例 #1
0
        public static void Run()
        {
            try
            {
                // ExStart:RemoveRights               
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
                string input = dataDir + "DigitallySign.pdf";
                using (PdfFileSignature pdfSign = new PdfFileSignature())
                {
                    pdfSign.BindPdf(input);
                    if (pdfSign.ContainsUsageRights())
                    {
                        pdfSign.RemoveUsageRights();
                    }

                    pdfSign.Document.Save(dataDir + "RemoveRights_out.pdf");
                }
                // ExEnd:RemoveRights
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }       
コード例 #2
0
 public static void Run()
 {
     try
     {
         // ExStart:DigitallySignature
         string pbxFile = "";
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         // Create PdfFileSignature object and bind input and output PDF files
         PdfFileSignature pdfSign = new PdfFileSignature();
         pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
         // Create a rectangle for signature location
         System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
         // Set signature appearance
         pdfSign.SignatureAppearance = dataDir + "aspose-logo.jpg";
         // Create any of the three signature types
         PKCS1 signature = new PKCS1(pbxFile, "password"); // PKCS#1 or
         
         pdfSign.Sign(1, "Signature Reason", "Contact", "Location", true, rect, signature);
         // Save output PDF file
         pdfSign.Save(dataDir + "DigitallySignature_out.pdf");
         // ExEnd:DigitallySignature
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #3
0
        public static void AddSignatureFields()
        {
            // ExStart:AddSignatureFields
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();
            Document doc = new Document(dataDir + "inFile.pdf");
            // Create FormEditor object
            FormEditor editor = new FormEditor(doc);
            // Add signature fields
            editor.AddField(FieldType.Signature, "Signature from Alice", 1, 10, 10, 110, 110);
            editor.AddField(FieldType.Signature, "Signature from John", 1, 120, 150, 220, 250);
            editor.AddField(FieldType.Signature, "Signature from Smith", 1, 300, 200, 400, 300);
            // Save the form
            editor.Save(dataDir + "AddSignatureFields_1_out.pdf");

            Document doc2 = new Document(dataDir + "inFile2.pdf");
            // Add signature to any of the signature fields
            PdfFileSignature pdfSign = new PdfFileSignature(doc2);
            pdfSign.Sign("Signature from John", "Signature Reason", "John", "Kharkov", new PKCS1("inFile1.pdf", "password"));
            // Each time new signature is added you must save the document
            pdfSign.Save(dataDir + "AddSignatureFields_2_out.pdf");

            Document doc3 = new Document(dataDir + "FilledForm.pdf");
            // Add second signature
            PdfFileSignature pdfSign2 = new PdfFileSignature(doc3);
            pdfSign2.Sign("Signature from Alice", "Signature Reason", "Alice", "Odessa", new PKCS1(dataDir + "FilledForm - 2.pfx", "password"));
            // Each time new signature is added you must save the document
            pdfSign2.Save(dataDir + "AddSignatureFields_3_out.pdf");
            // ExEnd:AddSignatureFields
        }
コード例 #4
0
        public static void AddSignatureFields()
        {
            // ExStart:AddSignatureFields
            // The path to the documents directory.
            string   dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();
            Document doc     = new Document(dataDir + "inFile.pdf");
            // Create FormEditor object
            FormEditor editor = new FormEditor(doc);

            // Add signature fields
            editor.AddField(FieldType.Signature, "Signature from Alice", 1, 10, 10, 110, 110);
            editor.AddField(FieldType.Signature, "Signature from John", 1, 120, 150, 220, 250);
            editor.AddField(FieldType.Signature, "Signature from Smith", 1, 300, 200, 400, 300);
            // Save the form
            editor.Save(dataDir + "AddSignatureFields_1_out.pdf");

            Document doc2 = new Document(dataDir + "inFile2.pdf");
            // Add signature to any of the signature fields
            PdfFileSignature pdfSign = new PdfFileSignature(doc2);

            pdfSign.Sign("Signature from John", "Signature Reason", "John", "Kharkov", new PKCS1("inFile1.pdf", "password"));
            // Each time new signature is added you must save the document
            pdfSign.Save(dataDir + "AddSignatureFields_2_out.pdf");

            Document doc3 = new Document(dataDir + "FilledForm.pdf");
            // Add second signature
            PdfFileSignature pdfSign2 = new PdfFileSignature(doc3);

            pdfSign2.Sign("Signature from Alice", "Signature Reason", "Alice", "Odessa", new PKCS1(dataDir + "FilledForm - 2.pfx", "password"));
            // Each time new signature is added you must save the document
            pdfSign2.Save(dataDir + "AddSignatureFields_3_out.pdf");
            // ExEnd:AddSignatureFields
        }
コード例 #5
0
 public static void Run()
 {
     try
     {
         // ExStart:RemoveSignature
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         // Create PdfFileSignature object
         PdfFileSignature pdfSign = new PdfFileSignature();
         // Open PDF document
         pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
         // Get list of signature names
         IList names = pdfSign.GetSignNames();
         // Remove all the signatures from the PDF file
         for (int index = 0; index < names.Count; index++)
         {
             pdfSign.RemoveSignature((string)names[index]);
         }
         // Save updated PDF file
         pdfSign.Save(dataDir + "RemoveSignature_out_.pdf");
         // ExEnd:RemoveSignature
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #6
0
        public static void Run()
        {
            try
            {
                // ExStart:DigitallySignature
                string pbxFile = "";
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
                // Create PdfFileSignature object and bind input and output PDF files
                PdfFileSignature pdfSign = new PdfFileSignature();
                pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
                // Create a rectangle for signature location
                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
                // Set signature appearance
                pdfSign.SignatureAppearance = dataDir + "aspose-logo.jpg";
                // Create any of the three signature types
                PKCS1 signature = new PKCS1(pbxFile, "password"); // PKCS#1 or

                pdfSign.Sign(1, "Signature Reason", "Contact", "Location", true, rect, signature);
                // Save output PDF file
                pdfSign.Save(dataDir + "DigitallySignature_out.pdf");
                // ExEnd:DigitallySignature
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #7
0
        public static void Run()
        {
            try
            {
                // ExStart:RemoveRights
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
                string input   = dataDir + "DigitallySign.pdf";
                using (PdfFileSignature pdfSign = new PdfFileSignature())
                {
                    pdfSign.BindPdf(input);
                    if (pdfSign.ContainsUsageRights())
                    {
                        pdfSign.RemoveUsageRights();
                    }

                    pdfSign.Document.Save(dataDir + "RemoveRights_out_.pdf");
                }
                // ExEnd:RemoveRights
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #8
0
        public static void Run()
        {
            // ExStart:HideDigitallySignedByCaption
            // The path to the documents directory.
            string dataDir   = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
            string inPfxFile = dataDir + "SampleCertificate.pfx";
            string inFile    = dataDir + "input.pdf";
            string outFile   = dataDir + "output.pdf";

            using (PdfFileSignature pdfSign = new PdfFileSignature())
            {
                pdfSign.BindPdf(inFile);
                //create a rectangle for signature location
                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(310, 45, 200, 50);

                //create any of the three signature types
                PKCS7 pkcs = new PKCS7(inPfxFile, "idsrv3test");
                SignatureCustomAppearance signatureCustomAppearance = new SignatureCustomAppearance();
                signatureCustomAppearance.FontSize           = 6;
                signatureCustomAppearance.FontFamilyName     = "Times New Roman";
                signatureCustomAppearance.DigitalSignedLabel = "Signed by me";
                pkcs.CustomAppearance = signatureCustomAppearance;
                // sign the PDF file
                pdfSign.Sign(1, true, rect, pkcs);
                //save output PDF file
                pdfSign.Save(outFile);
            }
            // ExEnd:HideDigitallySignedByCaption
        }
コード例 #9
0
 public static void Run()
 {
     try
     {
         // ExStart:RemoveSignature                
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         // Create PdfFileSignature object
         PdfFileSignature pdfSign = new PdfFileSignature();
         // Open PDF document
         pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
         // Get list of signature names
         IList names = pdfSign.GetSignNames();
         // Remove all the signatures from the PDF file
         for (int index = 0; index < names.Count; index++)
         {
             pdfSign.RemoveSignature((string)names[index]);
         }
         // Save updated PDF file
         pdfSign.Save(dataDir + "RemoveSignature_out.pdf");
         // ExEnd:RemoveSignature
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #10
0
        void oldVerify()
        {
            bool hasCert      = false;
            bool verifiedCert = false;

            // Load PDF document
            using (Document pdfDocument = new Document("c:\\temp\\valid signed contract.pdf"))
            {
                using (PdfFileSignature signature = new PdfFileSignature(pdfDocument))
                {
                    IList <string> sigNames = signature.GetSignNames();
                    if (sigNames.Count > 0)                     // Any signatures?
                    {
                        verifiedCert = signature.VerifySignature(sigNames[0] as string);
                        if (signature.VerifySigned(sigNames[0] as string))                                      // Verify first one
                        {
                            if (signature.IsCertified)                                                          // Certified?
                            {
                                if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission
                                {
                                    // Do something
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #11
0
        private static void Run_34561_tests()
        {
            // ExStart:Run_34561_tests
            new License().SetLicense(@"E:\Aspose.Pdf.lic");
            string inSingleSignedFile      = @"C:\pdftest\PDFNEWNET_34561_SingleSigned.pdf";
            string outSingleUnsignedFile   = @"C:\pdftest\PDFNEWNET_34561_SingleUnSigned.pdf";
            string inOutSingleResignedFile = @"C:\pdftest\PDFNEWNET_34561_SingleReSigned.pdf";

            PdfFileSignature pdfSignSingle = new PdfFileSignature();

            pdfSignSingle.BindPdf(inSingleSignedFile);
            IList  names         = pdfSignSingle.GetSignNames();
            Stream pfx           = new FileStream(@"C:\pdftest\test1.pfx", FileMode.Open);
            PKCS7  pcks          = new PKCS7(pfx, "test1");
            string sigNameSingle = names[0] as string;

            if (sigNameSingle != null && sigNameSingle != string.Empty)
            {
                pdfSignSingle.RemoveSignature(sigNameSingle, false);
                pdfSignSingle.Save(outSingleUnsignedFile);

                PdfFileSignature pdfSignSingle2 = new PdfFileSignature();
                pdfSignSingle2.BindPdf(outSingleUnsignedFile);
                pdfSignSingle2.SignatureAppearance = @"C:\pdftest\butterfly.jpg";
                pdfSignSingle2.Sign("Signature1", pcks);
                pdfSignSingle2.Save(inOutSingleResignedFile);
                pdfSignSingle2.BindPdf(inOutSingleResignedFile);
                // Assert.True(pdfSignSingle2.VerifySignature("Signature1"));
                Console.Write("Signature 1 check result : " + pdfSignSingle2.VerifySignature("Signature1").ToString() + " \n");
            }

            // Test file with multiple signatures
            string           outManyUnsignedFile   = @"C:\pdftest\PDFNEWNET_34561_ManyUnSigned.pdf";
            string           inOutManyResignedFile = @"C:\pdftest\PDFNEWNET_34561_ManyReSigned.pdf";
            PdfFileSignature pdfSignMany           = new Aspose.Pdf.Facades.PdfFileSignature();

            IList sigNames = pdfSignMany.GetSignNames();

            foreach (string sigName in sigNames)
            {
                pdfSignMany.RemoveSignature(sigName, false);
            }

            pdfSignMany.Save(outManyUnsignedFile);

            PdfFileSignature pdfSignMany2 = new PdfFileSignature();

            pdfSignMany2.BindPdf(outManyUnsignedFile);
            pdfSignMany2.Sign("Signature1", pcks);
            pdfSignMany2.Save(inOutManyResignedFile);
            pdfSignMany2.BindPdf(inOutSingleResignedFile);
            // Assert.IsTrue(pdfSignMany2.VerifySignature("Signature1"));
            Console.Write("Signature 2 check result : " + pdfSignMany2.VerifySignature("Signature1").ToString() + " ");
            // ExEnd:Run_34561_tests
        }
コード例 #12
0
        public static void Run()
        {
            try
            {
                // ExStart:DigitallySign
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
                string pbxFile = "";
                string inFile = dataDir + @"DigitallySign.pdf";
                string outFile = dataDir + @"DigitallySign_out.pdf";
                using (Document document = new Document(inFile))
                {
                    using (PdfFileSignature signature = new PdfFileSignature(document))
                    {
                        PKCS7 pkcs = new PKCS7(pbxFile, "WebSales"); // Use PKCS7/PKCS7Detached objects
                        DocMDPSignature docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms);
                        System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
                        // Set signature appearance
                        signature.SignatureAppearance = dataDir + @"aspose-logo.jpg";
                        // Create any of the three signature types
                        signature.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature);
                        // Save output PDF file
                        signature.Save(outFile);
                    }
                }

                using (Document document = new Document(outFile))
                {
                    using (PdfFileSignature signature = new PdfFileSignature(document))
                    {
                        IList sigNames = signature.GetSignNames();
                        if (sigNames.Count > 0) // Any signatures?
                        {
                            if (signature.VerifySigned(sigNames[0] as string)) // Verify first one
                            {
                                if (signature.IsCertified) // Certified?
                                {
                                    if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission
                                    {
                                        // Do something
                                    }
                                }
                            }
                        }
                    }
                }
                // ExEnd:DigitallySign
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #13
0
        public static void Run()
        {
            try
            {
                // ExStart:DigitallySign
                // The path to the documents directory.
                string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
                string pbxFile = "";
                string inFile  = dataDir + @"DigitallySign.pdf";
                string outFile = dataDir + @"DigitallySign_out_.pdf";
                using (Document document = new Document(inFile))
                {
                    using (PdfFileSignature signature = new PdfFileSignature(document))
                    {
                        PKCS7                    pkcs            = new PKCS7(pbxFile, "WebSales"); // Use PKCS7/PKCS7Detached objects
                        DocMDPSignature          docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms);
                        System.Drawing.Rectangle rect            = new System.Drawing.Rectangle(100, 100, 200, 100);
                        // Set signature appearance
                        signature.SignatureAppearance = dataDir + @"aspose-logo.jpg";
                        // Create any of the three signature types
                        signature.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature);
                        // Save output PDF file
                        signature.Save(outFile);
                    }
                }

                using (Document document = new Document(outFile))
                {
                    using (PdfFileSignature signature = new PdfFileSignature(document))
                    {
                        IList sigNames = signature.GetSignNames();
                        if (sigNames.Count > 0)                                                                     // Any signatures?
                        {
                            if (signature.VerifySigned(sigNames[0] as string))                                      // Verify first one
                            {
                                if (signature.IsCertified)                                                          // Certified?
                                {
                                    if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission
                                    {
                                        // Do something
                                    }
                                }
                            }
                        }
                    }
                }
                // ExEnd:DigitallySign
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #14
0
        public static void VerifyPDFSigned()
        {
            // ExStart:VerifyPDFSigned               
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();

            PdfFileSignature pdfSign = new PdfFileSignature();
            pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
            pdfSign.ContainsSignature();
            // Any signatures?
            pdfSign.Close();
            // ExEnd:VerifyPDFSigned  
        }
コード例 #15
0
        private static void Run_34561_tests()
        {
            // ExStart:Run_34561_tests
            new License().SetLicense(@"E:\Aspose.Pdf.lic");
            string inSingleSignedFile = @"C:\pdftest\PDFNEWNET_34561_SingleSigned.pdf";
            string outSingleUnsignedFile = @"C:\pdftest\PDFNEWNET_34561_SingleUnSigned.pdf";
            string inOutSingleResignedFile = @"C:\pdftest\PDFNEWNET_34561_SingleReSigned.pdf";

            PdfFileSignature pdfSignSingle = new PdfFileSignature();
            pdfSignSingle.BindPdf(inSingleSignedFile);
            IList names = pdfSignSingle.GetSignNames();
            Stream pfx = new FileStream(@"C:\pdftest\test1.pfx", FileMode.Open);
            PKCS7 pcks = new PKCS7(pfx, "test1");
            string sigNameSingle = names[0] as string;
            if (sigNameSingle != null && sigNameSingle != string.Empty)
            {
                pdfSignSingle.RemoveSignature(sigNameSingle, false);
                pdfSignSingle.Save(outSingleUnsignedFile);

                PdfFileSignature pdfSignSingle2 = new PdfFileSignature();
                pdfSignSingle2.BindPdf(outSingleUnsignedFile);
                pdfSignSingle2.SignatureAppearance = @"C:\pdftest\butterfly.jpg";
                pdfSignSingle2.Sign("Signature1", pcks);
                pdfSignSingle2.Save(inOutSingleResignedFile);
                pdfSignSingle2.BindPdf(inOutSingleResignedFile);
                // Assert.True(pdfSignSingle2.VerifySignature("Signature1"));
                Console.Write("Signature 1 check result : " + pdfSignSingle2.VerifySignature("Signature1").ToString() + " \n");
            }

            // Test file with multiple signatures         
            string outManyUnsignedFile = @"C:\pdftest\PDFNEWNET_34561_ManyUnSigned.pdf";
            string inOutManyResignedFile = @"C:\pdftest\PDFNEWNET_34561_ManyReSigned.pdf";
            PdfFileSignature pdfSignMany = new Aspose.Pdf.Facades.PdfFileSignature();

            IList sigNames = pdfSignMany.GetSignNames();
            foreach (string sigName in sigNames)
            {
                pdfSignMany.RemoveSignature(sigName, false);
            }

            pdfSignMany.Save(outManyUnsignedFile);

            PdfFileSignature pdfSignMany2 = new PdfFileSignature();
            pdfSignMany2.BindPdf(outManyUnsignedFile);
            pdfSignMany2.Sign("Signature1", pcks);
            pdfSignMany2.Save(inOutManyResignedFile);
            pdfSignMany2.BindPdf(inOutSingleResignedFile);
            // Assert.IsTrue(pdfSignMany2.VerifySignature("Signature1"));
            Console.Write("Signature 2 check result : " + pdfSignMany2.VerifySignature("Signature1").ToString() + " ");
            // ExEnd:Run_34561_tests
        }
コード例 #16
0
        public static void VerifyPDFSigned()
        {
            // ExStart:VerifyPDFSigned
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();

            PdfFileSignature pdfSign = new PdfFileSignature();

            pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
            pdfSign.ContainsSignature();
            // Any signatures?
            pdfSign.Close();
            // ExEnd:VerifyPDFSigned
        }
コード例 #17
0
 public static void VerifySignatures()
 {
     // ExStart:VerifySignatures
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();
     // Create PdfFileSignature object
     PdfFileSignature pdfVerify = new PdfFileSignature();
     // Bind input PDF file
     pdfVerify.BindPdf(dataDir + "inFile.pdf");
     // Check if PDF contains signature
     bool isSigned = pdfVerify.ContainsSignature();
     // All signatures have names Signaure#, this names kit generates automatically
     bool isSignatureVerified = pdfVerify.VerifySignature("Signature1");
     // However we can set necessary name manualy if we use signature fields (see below)
     bool isSignatureVerified2 = pdfVerify.VerifySignature("Signature from Alice");
     // ExEnd:VerifySignatures
 }
        public static void Run()
        {
            // ExStart:1
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();

            File.Copy(dataDir + "blank.pdf", dataDir + "externalSignature1.pdf", true);
            using (FileStream fs = new FileStream(dataDir + "externalSignature1.pdf", FileMode.Open, FileAccess.ReadWrite))
            {
                using (Document doc = new Document(fs))
                {
                    SignatureField field1 = new SignatureField(doc.Pages[1], new Rectangle(100, 400, 10, 10));

                    // Sign with certificate selection in the windows certificate store
                    System.Security.Cryptography.X509Certificates.X509Store store = new System.Security.Cryptography.X509Certificates.X509Store(System.Security.Cryptography.X509Certificates.StoreLocation.CurrentUser);
                    store.Open(System.Security.Cryptography.X509Certificates.OpenFlags.ReadOnly);
                    // Manually chose the certificate in the store
                    System.Security.Cryptography.X509Certificates.X509Certificate2Collection sel = System.Security.Cryptography.X509Certificates.X509Certificate2UI.SelectFromCollection(store.Certificates, null, null, System.Security.Cryptography.X509Certificates.X509SelectionFlag.SingleSelection);

                    Aspose.Pdf.Forms.ExternalSignature externalSignature = new Aspose.Pdf.Forms.ExternalSignature(sel[0])
                    {
                        Authority   = "Me",
                        Reason      = "Reason",
                        ContactInfo = "Contact"
                    };

                    field1.PartialName = "sig1";
                    doc.Form.Add(field1, 1);
                    field1.Sign(externalSignature);
                    doc.Save();
                }
            }

            using (PdfFileSignature pdfSign = new PdfFileSignature(new Document(dataDir + "externalSignature1.pdf")))
            {
                IList <string> sigNames = pdfSign.GetSignNames();
                for (int index = 0; index <= sigNames.Count - 1; index++)
                {
                    if (!pdfSign.VerifySigned(sigNames[index]) || !pdfSign.VerifySignature(sigNames[index]))
                    {
                        throw new ApplicationException("Not verified");
                    }
                }
            }
            // ExEnd:1
        }
コード例 #19
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            string inFile  = dataDir + @"input.pdf";
            string outFile = dataDir + @"output.pdf";

            using (Document document = new Document(inFile))
            {
                using (PdfFileSignature signature = new PdfFileSignature(document))
                {
                    PKCS7                    pkcs            = new PKCS7(@"c:\test.pfx", "WebSales"); // Use PKCS7/PKCS7Detached objects
                    DocMDPSignature          docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms);
                    System.Drawing.Rectangle rect            = new System.Drawing.Rectangle(100, 100, 200, 100);
                    //set signature appearance
                    signature.SignatureAppearance = dataDir + @"aspose-logo.jpg";
                    //create any of the three signature types
                    signature.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature);
                    //save output PDF file
                    signature.Save(outFile);
                }
            }

            using (Document document = new Document(outFile))
            {
                using (PdfFileSignature signature = new PdfFileSignature(document))
                {
                    IList sigNames = signature.GetSignNames();
                    if (sigNames.Count > 0)                                                                     // Any signatures?
                    {
                        if (signature.VerifySigned(sigNames[0] as string))                                      // Verify first one
                        {
                            if (signature.IsCertified)                                                          // Certified?
                            {
                                if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission
                                {
                                    // Do something
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #20
0
        public static void VerifySignatures()
        {
            // ExStart:VerifySignatures
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();
            // Create PdfFileSignature object
            PdfFileSignature pdfVerify = new PdfFileSignature();

            // Bind input PDF file
            pdfVerify.BindPdf(dataDir + "inFile.pdf");
            // Check if PDF contains signature
            bool isSigned = pdfVerify.ContainsSignature();
            // All signatures have names Signaure#, this names kit generates automatically
            bool isSignatureVerified = pdfVerify.VerifySignature("Signature1");
            // However we can set necessary name manualy if we use signature fields (see below)
            bool isSignatureVerified2 = pdfVerify.VerifySignature("Signature from Alice");
            // ExEnd:VerifySignatures
        }
コード例 #21
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            string inFile = dataDir+ @"input.pdf";
            string outFile = dataDir + @"output.pdf";
            using (Document document = new Document(inFile))
            {
                using (PdfFileSignature signature = new PdfFileSignature(document))
                {
                    PKCS7 pkcs = new PKCS7(@"c:\test.pfx", "WebSales"); // Use PKCS7/PKCS7Detached objects
                    DocMDPSignature docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms);
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
                    //set signature appearance
                    signature.SignatureAppearance = dataDir + @"aspose-logo.jpg";
                    //create any of the three signature types
                    signature.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature);
                    //save output PDF file
                    signature.Save(outFile);
                }
            }

            using (Document document = new Document(outFile))
            {
                using (PdfFileSignature signature = new PdfFileSignature(document))
                {
                    IList sigNames = signature.GetSignNames();
                    if (sigNames.Count > 0) // Any signatures?
                    {
                        if (signature.VerifySigned(sigNames[0] as string)) // Verify first one
                        {
                            if (signature.IsCertified) // Certified?
                            {
                                if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission
                                {
                                    // Do something
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #22
0
 public static void Run()
 {
     try
     {
         // ExStart:VerifyValidSignature
         // The path to the documents directory.
         string           dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         PdfFileSignature pdfSign = new PdfFileSignature();
         pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
         if (pdfSign.VerifySignature("Signature1"))
         {
             Console.WriteLine("Signature Verified");
         }
         // ExEnd:VerifyValidSignature
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #23
0
 public static void Run()
 {
     try
     {
         // ExStart:VerifyValidSignature               
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         PdfFileSignature pdfSign = new PdfFileSignature();
         pdfSign.BindPdf(dataDir + "DigitallySign.pdf");
         if (pdfSign.VerifySignature("Signature1"))
         {
             Console.WriteLine("Signature Verified");
         }
         // ExEnd:VerifyValidSignature
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }       
コード例 #24
0
        public static void Run()
        {
            // ExStart:PDFSigningMechanism
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            Document doc = new Document(dataDir + "inFile.pdf");
            // Create PdfFileSignature object and bind input and output PDF files
            PdfFileSignature pdfSign = new PdfFileSignature(doc);
            // Create a rectangle for signature location
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
            // Set signature appearance
            pdfSign.SignatureAppearance = dataDir + "aspose-logo.jpg";
           
            // Create any of the three signature types
            PKCS1 signature = new PKCS1(dataDir + "inFile2.pdf", "password"); 
         
            pdfSign.Sign(1, "Signature Reason", "Alice", "Odessa", true, rect, signature);         
            // ExEnd:PDFSigningMechanism                      
        }
コード例 #25
0
 public static void Run()
 {
     try
     {
         // ExStart:ExtractSignatureInfo
         // The path to the documents directory.
         string dataDir   = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         string input     = dataDir + "DigitallySign.pdf";
         string pkcs1File = "";
         using (PdfFileSignature pdfFileSignature = new PdfFileSignature())
         {
             pdfFileSignature.BindPdf(input);
             IList <string> sigNames = pdfFileSignature.GetSignNames();
             if (sigNames.Count > 0)
             {
                 string sigName = sigNames[0] as string;
                 if (string.IsNullOrEmpty(sigName))
                 {
                     Stream cerStream = pdfFileSignature.ExtractCertificate(sigName);
                     if (cerStream != null)
                     {
                         using (cerStream)
                         {
                             byte[] bytes = new byte[cerStream.Length];
                             using (FileStream fs = new FileStream(dataDir + pkcs1File, FileMode.CreateNew))
                             {
                                 cerStream.Read(bytes, 0, bytes.Length);
                                 fs.Write(bytes, 0, bytes.Length);
                             }
                         }
                     }
                 }
             }
         }
         // ExEnd:ExtractSignatureInfo
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
コード例 #26
0
 public static void Run()
 {
     try
     {
         // ExStart:ExtractSignatureInfo               
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         string input = dataDir + "DigitallySign.pdf";
         string pkcs1File = "";
         using (PdfFileSignature pdfFileSignature = new PdfFileSignature())
         {
             pdfFileSignature.BindPdf(input);
             IList sigNames = pdfFileSignature.GetSignNames();
             if (sigNames.Count > 0)
             {
                 string sigName = sigNames[0] as string;
                 if (string.IsNullOrEmpty(sigName))
                 {
                     Stream cerStream = pdfFileSignature.ExtractCertificate(sigName);
                     if (cerStream != null)
                     {
                         using (cerStream)
                         {
                             byte[] bytes = new byte[cerStream.Length];
                             using (FileStream fs = new FileStream(dataDir + pkcs1File, FileMode.CreateNew))
                             {
                                 cerStream.Read(bytes, 0, bytes.Length);
                                 fs.Write(bytes, 0, bytes.Length);
                             }
                         }
                     }
                 }
             }
         }
         // ExEnd:ExtractSignatureInfo
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }       
コード例 #27
0
        public static void Run()
        {
            // ExStart:PDFSigningMechanism
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdfFacades_TechnicalArticles();

            Document doc = new Document(dataDir + "inFile.pdf");
            // Create PdfFileSignature object and bind input and output PDF files
            PdfFileSignature pdfSign = new PdfFileSignature(doc);

            // Create a rectangle for signature location
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
            // Set signature appearance
            pdfSign.SignatureAppearance = dataDir + "aspose-logo.jpg";

            // Create any of the three signature types
            PKCS1 signature = new PKCS1(dataDir + "inFile2.pdf", "password");

            pdfSign.Sign(1, "Signature Reason", "Alice", "Odessa", true, rect, signature);
            // ExEnd:PDFSigningMechanism
        }
コード例 #28
0
 public static void Run()
 {
     // ExStart:DigitallySignWithTimeStamp
     // The path to the documents directory.
     string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
     string pfxFile = "";
     using (Document document = new Document(dataDir + @"DigitallySign.pdf"))
     {
         using (PdfFileSignature signature = new PdfFileSignature(document))
         {
             PKCS7 pkcs = new PKCS7(pfxFile, "pfx_password");
             TimestampSettings timestampSettings = new TimestampSettings("https:\\your_timestamp_settings", "user:password"); // User/Password can be omitted
             pkcs.TimestampSettings = timestampSettings;
             System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
             // Create any of the three signature types
             signature.Sign(1, "Signature Reason", "Contact", "Location", true, rect, pkcs);
             // Save output PDF file
             signature.Save(dataDir + "DigitallySignWithTimeStamp_out.pdf");
         }
     }
     // ExEnd:DigitallySignWithTimeStamp
 }
コード例 #29
0
        public static void Run()
        {
            // ExStart:DigitallySignWithTimeStamp
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
            string pfxFile = "";

            using (Document document = new Document(dataDir + @"DigitallySign.pdf"))
            {
                using (PdfFileSignature signature = new PdfFileSignature(document))
                {
                    PKCS7             pkcs = new PKCS7(pfxFile, "pfx_password");
                    TimestampSettings timestampSettings = new TimestampSettings("https:\\your_timestamp_settings", "user:password"); // User/Password can be omitted
                    pkcs.TimestampSettings = timestampSettings;
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
                    // Create any of the three signature types
                    signature.Sign(1, "Signature Reason", "Contact", "Location", true, rect, pkcs);
                    // Save output PDF file
                    signature.Save(dataDir + "DigitallySignWithTimeStamp_out_.pdf");
                }
            }
            // ExEnd:DigitallySignWithTimeStamp
        }
コード例 #30
0
 public static void Run()
 {
     try
     {
         // ExStart:ExtractImages               
         // The path to the documents directory.
         string dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         string input = dataDir + "DigitallySign.pdf";
         Document doc = new Document(input);
         using (PdfFileSignature signature = new PdfFileSignature(doc))
         {
             if (signature.ContainsSignature())
             {
                 foreach (string sigName in signature.GetSignNames())
                 {
                     string outFile = dataDir + "ExtractImages_out.jpg";
                     using (Stream imageStream = signature.ExtractImage(sigName))
                     {
                         if (imageStream != null)
                         {
                             using (System.Drawing.Image image = Bitmap.FromStream(imageStream))
                             {
                                 image.Save(outFile, ImageFormat.Jpeg);
                             }
                         }
                     }
                 }
             }
         }
         // ExEnd:ExtractImages
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }       
コード例 #31
0
 public static void Run()
 {
     try
     {
         // ExStart:ExtractImages
         // The path to the documents directory.
         string   dataDir = RunExamples.GetDataDir_AsposePdfFacades_SecuritySignatures();
         string   input   = dataDir + "DigitallySign.pdf";
         Document doc     = new Document(input);
         using (PdfFileSignature signature = new PdfFileSignature(doc))
         {
             if (signature.ContainsSignature())
             {
                 foreach (string sigName in signature.GetSignNames())
                 {
                     string outFile = dataDir + "ExtractImages_out.jpg";
                     using (Stream imageStream = signature.ExtractImage(sigName))
                     {
                         if (imageStream != null)
                         {
                             using (System.Drawing.Image image = Bitmap.FromStream(imageStream))
                             {
                                 image.Save(outFile, ImageFormat.Jpeg);
                             }
                         }
                     }
                 }
             }
         }
         // ExEnd:ExtractImages
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }