private void handleSigGenEvent(SignatureType type)
 {
     if (type == SignatureType.Pkcs1)
     {
         this.signature = (RsaSig)SignatureHandler.getInstance().getSignature();
         this.setEnabled();
         this.rbSigPkcs.IsEnabled = true;
         this.rbSigPkcs.IsChecked = true;
         this.rbSigPkcs.Content   = SigValCtrl.rsaSig;
         this.ResultEmpty();
     }
     else if (type == SignatureType.Bleichenbacher)
     {
         this.signature = (BleichenbacherSig)SignatureHandler.getInstance().getBleichenbSig();
         this.setEnabled();
         this.rbSigBlei.IsEnabled = true;
         this.rbSigBlei.IsChecked = true;
         this.rbSigBlei.Content   = SigValCtrl.bleichenbSig;
         this.ResultEmpty();
     }
     else if (type == SignatureType.Kuehn)
     {
         this.signature = (KuehnSig)SignatureHandler.getInstance().getKuehnSig();
         this.setEnabled();
         this.rbSigKuehn.IsEnabled = true;
         this.rbSigKuehn.IsChecked = true;
         this.rbSigKuehn.Content   = SigValCtrl.kuehnSig;
         this.ResultEmpty();
     }
 }
        public static void WordsDocument()
        {
            // set up Signature configuration
            SignatureConfig signConfig = Helper.GetPaths();

            // instantiating the conversion handler
            var handler = new SignatureHandler(signConfig);
            // setup digital signature options
            var signOptions = new WordsSignDigitalOptions("test.pfx");

            //
            signOptions.Password           = "******";
            signOptions.Left               = 10;
            signOptions.Top                = 10;
            signOptions.Width              = 100;
            signOptions.Height             = 100;
            signOptions.DocumentPageNumber = 1;

            // sign document
            var signedPath = handler.Sign <string>("test.docx", signOptions, new SaveOptions {
                OutputType = OutputType.String
            });

            Console.WriteLine("Signed file path is: " + signedPath);
        }
Exemple #3
0
        public void CustomStorageTest(string inputFileName)
        {
            SignatureConfig config     = new SignatureConfig();
            string          rootPath   = Path.GetFullPath(@"..\..\");
            string          imagesPath = Path.Combine(rootPath, @"Images");

            string fileName;

            SaveOptions       saveOptions = new SaveOptions(OutputType.String);
            IInputDataHandler customInputStorageProvider = new SampleAzureInputDataHandler(DevStorageEmulatorUrl,
                                                                                           DevStorageEmulatorAccountName, DevStorageEmulatorAccountKey, "testbucket");
            IOutputDataHandler customOutputStorageProvider = new SampleAzureOutputDataHandler(
                DevStorageEmulatorUrl, DevStorageEmulatorAccountName, DevStorageEmulatorAccountKey, "tempbucket");
            SignatureHandler handlerWithCustomStorage = new SignatureHandler(config, customInputStorageProvider, customOutputStorageProvider);

            LicenseSetter.SetSignatureLicense(handlerWithCustomStorage);

            using (Stream imageStream = File.OpenRead(Path.Combine(imagesPath, "Autograph_of_Benjamin_Franklin.png")))
            {
                PdfSignImageOptions options = new PdfSignImageOptions(imageStream);
                options.DocumentPageNumber = 1;
                options.Top    = 500;
                options.Width  = 200;
                options.Height = 100;
                fileName       = handlerWithCustomStorage.Sign <string>(inputFileName, options, saveOptions);
            }
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);
        }
Exemple #4
0
        static void Main(string[] args)
        {
            string rootPath    = Path.GetFullPath(@"..\..\");
            string storagePath = Path.Combine(rootPath, @"Storage");
            string outputPath  = Path.Combine(rootPath, @"Output");
            string imagesPath  = Path.Combine(rootPath, @"Images");

            // setup a configuration
            SignatureConfig config = new SignatureConfig()
            {
                StoragePath = storagePath,
                OutputPath  = outputPath,
                ImagesPath  = imagesPath
            };

            // instantiating the handler
            SignatureHandler handler = new SignatureHandler(config);

            // setup Cells text signature options
            CellsSignTextOptions cellsOptions = new CellsSignTextOptions(@"Test signature");

            cellsOptions.SheetNumber  = 1;
            cellsOptions.ColumnNumber = 0;
            cellsOptions.RowNumber    = 0;
            cellsOptions.Width        = 150;
            cellsOptions.Height       = 50;
            cellsOptions.SignAllPages = true;

            SaveOptions saveOptions = new SaveOptions(OutputType.String);

            // Set a license if you have one
            License license = new License();

            license.SetLicense(@"GroupDocs.Signature3.lic");

            // sign the document
            string fileName = handler.Sign <string>(@"test.xlsx", cellsOptions, saveOptions);

            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);

            LoadOptions loadOptions = new LoadOptions();

            loadOptions.Password = "******";
            fileName             = handler.Sign <string>(@"testPassword123.xlsx", cellsOptions, loadOptions, saveOptions);
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);

            saveOptions = new SaveOptions(OutputType.Stream);
            using (Stream stream = handler.Sign <Stream>(@"test.xlsx", cellsOptions, saveOptions))
            {
                stream.Seek(0, SeekOrigin.Begin);
            }

            saveOptions = new SaveOptions(OutputType.String);
            using (Stream fileStream = File.OpenRead(Path.Combine(storagePath, "test.xlsx")))
            {
                fileName = handler.Sign <string>(fileStream, cellsOptions, saveOptions);
            }
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);
        }
Exemple #5
0
        private void bExecute_Click(object sender, RoutedEventArgs e)
        {
            this.m_RSASignature = (RsaSig)SignatureHandler.getInstance().getSignature();
            this.m_RSASignature.GenerateSignature();
            UserControlHelper.loadRtbColoredSig(this.rtbResult, this.m_RSASignature.GetSignatureDecToHexString());
            this.tbResultEncrypted.Text = this.m_RSASignature.GetSignatureToHexString();

            // nur temp
            //SignatureHandler.getInstance().setSignature(this.m_RSASignature);
        }
        //ExEnd:Applylicense

        #region GetSourceDocsFromDifferentResources
        /// <summary>
        /// Get source document from absolute path
        /// </summary>
        public static void GetSrcDocFromAbsolutePath()
        {
            // instantiating the signature handler without Signature Config object
            var handler = new SignatureHandler();
            // setup image signature options
            var signOptions = new PdfSignImageOptions(@"C:\signature.jpg");
            // sign document with image
            var signedPath = handler.Sign <string>(@"C:\test.pdf", signOptions, new SaveOptions {
                OutputType = OutputType.String
            });

            Console.WriteLine("Signed file path is: " + signedPath);
        }
        public ActionResult GetDocumentPageImage(string path, int?width, int?quality, int pageIndex)
        {
            string appDataPath = Server.MapPath(AppDataVirtualPath);

            byte[] fileBytes = SignatureHandler.GetDocumentPageImage(Path.Combine(appDataPath, path), width, quality, pageIndex);
            if (fileBytes == null)
            {
                return(new EmptyResult());
            }
            else
            {
                return(File(fileBytes, "image/jpeg"));
            }
        }
Exemple #8
0
        private void bExecute_Click(object sender, RoutedEventArgs e)
        {
            Cursor = Cursors.Wait;

            this.m_BleichSignature = (BleichenbacherSig)SignatureHandler.getInstance().getBleichenbSig();
            this.m_BleichSignature.DataBlockStartPos = (int)this.cbPosDataBlock.SelectedValue;
            this.m_BleichSignature.ChangeSign        = this.tbChangeSign.Text;

            this.m_BleichSignature.GenerateSignature();
            UserControlHelper.loadRtbColoredSig(this.rtbResult, this.m_BleichSignature.GetSignatureDecToHexString());
            this.tbResultEncrypted.Text = this.m_BleichSignature.GetSignatureToHexString();

            SignatureHandler.getInstance().setBleichenBSig(this.m_BleichSignature);
            Cursor = Cursors.Arrow;
        }
Exemple #9
0
 /// <summary>
 /// 接入
 /// </summary>
 /// <param name="signature"></param>
 /// <param name="timestamp"></param>
 /// <param name="nonce"></param>
 /// <param name="echostr"></param>
 /// <returns></returns>
 public HttpResponseMessage get(string signature, string timestamp, string nonce, string echostr)
 {
     try
     {
         LogHelper.Info(this, string.Format("signature:{0},timestamp:{1},nonce:{2},echostr:{3},token:{4}", signature, timestamp, nonce, echostr, token));
         if (SignatureHandler.CheckSignature(token, signature, timestamp, nonce))
         {
             return(ToHttpMsgForWeChat(echostr));
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error(this, "验证微信接口代码错误:" + ex.Message + ex.InnerException.Message);
     }
     return(ToHttpMsgForWeChat("验证失败"));
 }
Exemple #10
0
        public void Init()
        {
            //TODO: dreifaches anmelden anders lösen?
            SignatureHandler.getInstance().getSignature().RaiseSigGenEvent    += handleSigGenEvent;
            SignatureHandler.getInstance().getBleichenbSig().RaiseSigGenEvent += handleSigGenEvent;
            SignatureHandler.getInstance().getKuehnSig().RaiseSigGenEvent     += handleSigGenEvent;

            this.rbVal.IsChecked = true;
            this.validator       = new SigValidator();

            this.rbSigBlei.IsEnabled  = false;
            this.rbSigBlei.Content    = SigValCtrl.bleichenbSig + " " + SigValCtrl.sigNotGeneratedYet;
            this.rbSigPkcs.IsEnabled  = false;
            this.rbSigPkcs.Content    = SigValCtrl.rsaSig + " " + SigValCtrl.sigNotGeneratedYet;
            this.rbSigKuehn.IsEnabled = false;
            this.rbSigKuehn.Content   = SigValCtrl.kuehnSig + " " + SigValCtrl.sigNotGeneratedYet;


            if (SignatureHandler.getInstance().isRsaSigGenerated())
            {
                this.signature = (RsaSig)SignatureHandler.getInstance().getSignature();
                this.setEnabled();
                this.rbSigPkcs.IsEnabled = true;
                this.rbSigPkcs.IsChecked = true;
                this.rbSigPkcs.Content   = SigValCtrl.rsaSig;
            }
            else if (SignatureHandler.getInstance().isBleichenbSigGenerated())
            {
                this.signature = (BleichenbacherSig)SignatureHandler.getInstance().getBleichenbSig();
                this.setEnabled();
                this.rbSigBlei.IsEnabled = true;
                this.rbSigBlei.IsChecked = true;
                this.rbSigBlei.Content   = SigValCtrl.bleichenbSig;
            }
            else if (SignatureHandler.getInstance().isKuehnSigGenerated())
            {
                this.signature = (KuehnSig)SignatureHandler.getInstance().getKuehnSig();
                this.setEnabled();
                this.rbSigKuehn.IsEnabled = true;
                this.rbSigKuehn.IsChecked = true;
                this.rbSigKuehn.Content   = SigValCtrl.kuehnSig;
            }
            else
            {
                this.setDisabled();
            }
        }
        private void bExecute_Click(object sender, RoutedEventArgs e)
        {
            Cursor = Cursors.Wait;

            if (this.Signature.GenerateSignature())
            {
                UserControlHelper.loadRtbColoredSig(this.rtbResult, this.Signature.GetSignatureDecToHexString());
                this.tbResultEncrypted.Text = this.Signature.GetSignatureToHexString();
                SignatureHandler.getInstance().setKuehnSig(this.Signature);
            }
            else
            {
                this.tbError.Text = SigGenKuehnCtrl.genSigErrorMaxIter;
            }

            Cursor = Cursors.Arrow;
        }
        static void Main(string[] args)
        {
            string rootPath    = Path.GetFullPath(@"..\..\");
            string storagePath = Path.Combine(rootPath, @"Storage");
            string outputPath  = Path.Combine(rootPath, @"Output");
            string imagesPath  = Path.Combine(rootPath, @"Images");

            PdfSignDigitalOptions pdfDigitalOptions = new PdfSignDigitalOptions(Path.Combine(storagePath, @"a.pfx"));

            // set coordinates of image
            pdfDigitalOptions.Left   = 10;
            pdfDigitalOptions.Top    = 10;
            pdfDigitalOptions.Width  = 100;
            pdfDigitalOptions.Height = 100;

            pdfDigitalOptions.ImageFileName = "Autograph_of_Benjamin_Franklin.png";

            // set document page number
            pdfDigitalOptions.DocumentPageNumber = 1;

            // set document password if required
            pdfDigitalOptions.Password = "******";

            // set up configuration
            SignatureConfig config = new SignatureConfig()
            {
                StoragePath = storagePath,
                OutputPath  = outputPath,
                ImagesPath  = imagesPath
            };
            // instantiating the handler
            SignatureHandler handler = new SignatureHandler(config);

            // Set a license if you have one
            License license = new License();

            license.SetLicense(@"GroupDocs.Signature3.lic");

            SaveOptions saveOptions = new SaveOptions(OutputType.String);

            // sign document
            string fileName = handler.Sign <string>(@"candy.pdf", pdfDigitalOptions, saveOptions);

            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);
        }
Exemple #13
0
        static void Main(string[] args)
        {
            string rootPath    = Path.GetFullPath(@"..\..\");
            string storagePath = Path.Combine(rootPath, @"Storage");
            string outputPath  = Path.Combine(rootPath, @"Output");
            string imagesPath  = Path.Combine(rootPath, @"Images");

            // setup a configuration
            SignatureConfig config = new SignatureConfig()
            {
                StoragePath = storagePath,
                OutputPath  = outputPath,
                ImagesPath  = imagesPath
            };

            // instantiating the handler
            SignatureHandler handler = new SignatureHandler(config);

            // Set a license if you have one
            License license = new License();

            license.SetLicense(@"GroupDocs.Signature3.lic");

            // setup Cells image signature options
            var cellsImageSignatureOptions = new CellsSignImageOptions(@"Autograph_of_Benjamin_Franklin.png");

            // set coordinates of image
            cellsImageSignatureOptions.Left   = 10;
            cellsImageSignatureOptions.Top    = 10;
            cellsImageSignatureOptions.Width  = 100;
            cellsImageSignatureOptions.Height = 100;

            // set document page number
            cellsImageSignatureOptions.SheetNumber  = 1;
            cellsImageSignatureOptions.ColumnNumber = 0;
            cellsImageSignatureOptions.RowNumber    = 5;
            cellsImageSignatureOptions.SignAllPages = false;

            SaveOptions saveOptions = new SaveOptions(OutputType.String);

            // sign the document
            string fileName = handler.Sign <string>(@"test.xlsx", cellsImageSignatureOptions, saveOptions);

            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);
        }
        /// <summary>
        /// Get source document from URI
        /// </summary>
        public static void GetSrcDocFromUri()
        {
            // setup Signature configuration
            var signConfig = new SignatureConfig
            {
                OutputPath = @"c:\Test\Output"
            };
            // instantiating the signature handler without Signature Config object
            var handler = new SignatureHandler(signConfig);
            // setup image signature options
            var signOptions = new PdfSignImageOptions(@"http://groupdocs.com/images/banner/carousel2/conversion.png");
            // save options
            var saveOptions = new SaveOptions(OutputType.String);
            // sign document with image
            var signedPath = handler.Sign <string>("https://www.adobe.com/content/dam/Adobe/en/feature-details/acrobatpro/pdfs/combine-multiple-documents-into-one-pdf-file.pdf", signOptions, saveOptions);

            Console.WriteLine("Signed file path is: " + signedPath);
        }
        public static void CellsDocument()
        {
            // set up Signature configuration
            SignatureConfig signConfig = Helper.GetPaths();

            // instantiating the conversion handler
            var handler = new SignatureHandler(signConfig);
            // setup digital signature options
            var signOptions = new CellsSignDigitalOptions("test.pfx");

            signOptions.Password = "******";

            // sign document
            var signedPath = handler.Sign <string>("test.xls", signOptions, new SaveOptions {
                OutputType = OutputType.String
            });

            Console.WriteLine("Signed file path is: " + signedPath);
        }
Exemple #16
0
        static void Main(string[] args)
        {
            string rootPath    = Path.GetFullPath(@"..\..\");
            string storagePath = Path.Combine(rootPath, @"Storage");
            string outputPath  = Path.Combine(rootPath, @"Output");
            string imagesPath  = Path.Combine(rootPath, @"Images");

            // setup a configuration
            SignatureConfig config = new SignatureConfig()
            {
                StoragePath = storagePath,
                OutputPath  = outputPath,
                ImagesPath  = imagesPath
            };

            // instantiating the handler
            SignatureHandler handler = new SignatureHandler(config);

            // setup PDF image signature options
            PdfSignImageOptions pdfImageSignatureOptions = new PdfSignImageOptions(@"Autograph_of_Benjamin_Franklin.png");

            pdfImageSignatureOptions.DocumentPageNumber = 1;
            pdfImageSignatureOptions.Top    = 500;
            pdfImageSignatureOptions.Width  = 50;
            pdfImageSignatureOptions.Height = 20;

            // Set a license if you have one
            License license = new License();

            license.SetLicense(@"GroupDocs.Signature3.lic");

            SaveOptions saveOptions = new SaveOptions(OutputType.String);
            // sign the document
            LoadOptions loadOptions = new LoadOptions();
            string      fileName    = handler.Sign <string>(@"candy.pdf", pdfImageSignatureOptions, saveOptions);

            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);

            loadOptions.Password = "******";
            fileName             = handler.Sign <string>(@"candyPassword123.pdf", pdfImageSignatureOptions, loadOptions, saveOptions);
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);
        }
        /// <summary>
        /// Get source document from Stream
        /// </summary>
        public static void GetSrcDocFromStream()
        {
            // setup Signature configuration
            var signConfig = new SignatureConfig
            {
                OutputPath = @"c:\Test\Output"
            };
            // instantiating the signature handler without Signature Config object
            var handler = new SignatureHandler(signConfig);
            // setup image signature options
            var signOptions = new PdfSignImageOptions(@"http://groupdocs.com/images/banner/carousel2/conversion.png");
            // save options
            var saveOptions = new SaveOptions(OutputType.String);

            using (var fileStream = new FileStream(@"C:\test.pdf", FileMode.Open, FileAccess.Read))
            {
                // sign document with image
                var signedPath = handler.Sign <string>(fileStream, signOptions, saveOptions);
                Console.WriteLine("Signed file path is: " + signedPath);
            }
        }
Exemple #18
0
        public static void CellsDocument()
        {
            // set up Signature configuration
            SignatureConfig signConfig = Helper.GetPaths();
            // instantiating the conversion handler
            var handler = new SignatureHandler(signConfig);
            // set text signature options
            var signOptions = new CellsSignTextOptions("John Smith");

            // text position
            signOptions.RowNumber          = 10;
            signOptions.ColumnNumber       = 10;
            signOptions.SignAllPages       = true;
            signOptions.DocumentPageNumber = 1;
            // sign document
            var signedPath = handler.Sign <string>("test.xls", signOptions, new SaveOptions {
                OutputType = OutputType.String
            });

            Console.WriteLine("Signed file path is: " + signedPath);
        }
Exemple #19
0
        public static void PDFDocument()
        {
            // setup Signature configuration
            SignatureConfig signConfig = Helper.GetPaths();

            // instantiating the conversion handler
            var handler = new SignatureHandler(signConfig);
            // setup text signature options
            var signOptions = new PdfSignTextOptions("John Smith");

            // text position
            signOptions.Left = 100;
            signOptions.Top  = 100;
            signOptions.DocumentPageNumber = 1;
            // sign document
            var signedPath = handler.Sign <string>("test.pdf", signOptions, new SaveOptions {
                OutputType = OutputType.String
            });

            Console.WriteLine("Signed file path is: " + signedPath);
        }
Exemple #20
0
        public static void WordsDocument()
        {
            // setup Signature configuration
            SignatureConfig signConfig = Helper.GetPaths();

            // instantiating the conversion handler
            var handler = new SignatureHandler(signConfig);
            // setup image signature options with relative path - image file stores in config.ImagesPath folder
            var signOptions = new WordsSignImageOptions("signature.jpg");

            signOptions.Left               = 10;
            signOptions.Top                = 10;
            signOptions.Width              = 100;
            signOptions.Height             = 100;
            signOptions.DocumentPageNumber = 1;
            // sign document
            var signedPath = handler.Sign <string>("test.docx", signOptions, new SaveOptions {
                OutputType = OutputType.String
            });

            Console.WriteLine("Signed file path is: " + signedPath);
        }
        /// <summary>
        /// Get source document from relative path
        /// </summary>
        public static void GetSrcDocFromRelaticePath()
        {
            var storagePath = @"c:\Test\Storage";
            var outputPath  = @"c:\Test\Output";
            var imagesPath  = @"c:\Test\Images";
            // setup Signature configuration
            var signConfig = new SignatureConfig
            {
                StoragePath = storagePath,
                OutputPath  = outputPath,
                ImagesPath  = imagesPath
            };
            // instantiating the conversion handler
            var handler = new SignatureHandler(signConfig);
            // setup image signature options with relative path - image file stores in config.ImagesPath folder
            var signOptions = new PdfSignImageOptions("signature.jpg");
            // sign document
            var signedPath = handler.Sign <string>("test.pdf", signOptions, new SaveOptions {
                OutputType = OutputType.String
            });

            Console.WriteLine("Signed file path is: " + signedPath);
        }
        static void Main(string[] args)
        {
            string rootPath    = Path.GetFullPath(@"..\..\");
            string storagePath = Path.Combine(rootPath, @"Storage");
            string outputPath  = Path.Combine(rootPath, @"Output");
            string imagesPath  = Path.Combine(rootPath, @"Images");

            // setup a configuration
            SignatureConfig config = new SignatureConfig()
            {
                StoragePath = storagePath,
                OutputPath  = outputPath,
                ImagesPath  = imagesPath
            };

            // instantiating the handler
            SignatureHandler handler = new SignatureHandler(config);

            // Set a license if you have one
            License license = new License();

            license.SetLicense(@"GroupDocs.Signature3.lic");

            // set up PDF image signature options
            PdfSignTextOptions signOptions = new PdfSignTextOptions(@"Test signature");

            signOptions.DocumentPageNumber = 1;
            signOptions.Left         = 100;
            signOptions.Top          = 0;
            signOptions.SignAllPages = true;

            SaveOptions saveOptions = new SaveOptions(OutputType.String);
            // sign the document
            string fileName = handler.Sign <string>(@"candy.pdf", signOptions, saveOptions);

            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);
        }
        public ActionResult ViewDocument(string path,
                                         int quality, int width)
        {
            string fileNameExtension = Path.GetExtension(path).TrimStart('.');

            fileNameExtension = fileNameExtension.ToLower();
            string appDataPath = Server.MapPath(AppDataVirtualPath);
            DocumentDescription documentDescription = SignatureHandler.GetPageDescriptions(Path.Combine(appDataPath, path));
            int pageCount = documentDescription.Pages.Count;

            string[]             pageImageUrls         = GetImageUrls(path, 0, pageCount, width, quality);
            UrlHelper            urlHelper             = new UrlHelper(Request.RequestContext);
            string               documentDownloadUrl   = urlHelper.Action("GetDocument", "Signature", new { path });
            JavaScriptSerializer serializer            = new JavaScriptSerializer();
            string               documentDescriptionJs = LowerCaseJsonSerializer.SerializeObject(documentDescription);
            var result = new
            {
                path,
                docType               = "Pdf",
                fileType              = fileNameExtension,
                url                   = documentDownloadUrl,
                pdfDownloadUrl        = (string)null,
                name                  = path,
                imageUrls             = pageImageUrls,
                lic                   = true,
                pdfPrintUrl           = (string)null,
                pageHtml              = (object)null,
                pageCss               = (object)null,
                documentDescription   = documentDescriptionJs,
                urlForResourcesInHtml = (object)null,
                sharedCss             = (object)null,
                success               = true
            };

            return(Json(result));
        }
Exemple #24
0
        static void Main(string[] args)
        {
            string rootPath    = Path.GetFullPath(@"..\..\");
            string storagePath = Path.Combine(rootPath, @"Storage");
            string outputPath  = Path.Combine(rootPath, @"Output");
            string imagesPath  = Path.Combine(rootPath, @"Images");

            // setup a storage configuration
            SignatureConfig config = new SignatureConfig()
            {
                StoragePath = storagePath,
                OutputPath  = outputPath,
                ImagesPath  = imagesPath
            };

            // instantiating the handler
            SignatureHandler handler = new SignatureHandler(config);

            // setup Words text signature options
            var options = new WordsSignTextOptions();

            // set the signature text, font family name and other properties
            options.Text   = "Test signature";
            options.Left   = 50;
            options.Top    = 300;
            options.Width  = 100;
            options.Height = 50;

            // put the signature on all the pages
            options.SignAllPages = true;

            SaveOptions saveOptions = new SaveOptions();

            saveOptions.OutputType = OutputType.String;

            // Set a license if you have one
            License license = new License();

            license.SetLicense(@"GroupDocs.Signature3.lic");

            // sign the documents
            string fileName;
            Stream resultStream;

            using (Stream fileStream = File.OpenRead(Path.Combine(storagePath, "test.docx")))
            {
                fileName = handler.Sign <string>(fileStream, options, saveOptions);
            }
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);

            using (Stream fileStream = File.OpenRead(Path.Combine(storagePath, "test.docx")))
            {
                saveOptions.OutputType = OutputType.Stream;
                resultStream           = handler.Sign <Stream>(fileStream, options, saveOptions);
                resultStream.Seek(0, SeekOrigin.Begin);
            }

            LoadOptions loadOptions = new LoadOptions();

            loadOptions.Password   = "******";
            saveOptions.OutputType = OutputType.String;
            fileName = handler.Sign <string>(Path.Combine(storagePath, @"test.docx"), options, loadOptions, saveOptions);
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);

            fileName = handler.Sign <string>(@"test.docx", options, loadOptions, saveOptions);
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);

            fileName = handler.Sign <string>(@"test1PagePassword123.docx", options, loadOptions, saveOptions);
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);

            saveOptions            = new SaveOptions(OutputType.Stream);
            saveOptions.OutputType = OutputType.Stream;
            using (Stream stream = handler.Sign <Stream>(@"test.docx", options, loadOptions, saveOptions))
            {
                stream.Seek(0, SeekOrigin.Begin);
            }
        }
Exemple #25
0
        internal static void SetSignatureLicense(SignatureHandler handler)
        {
            License license = new License();

            license.SetLicense(@"GroupDocs.Signature3.lic");
        }
Exemple #26
0
 private void rbSigKuehn_Checked(object sender, RoutedEventArgs e)
 {
     this.ResultEmpty();
     this.signature = (KuehnSig)SignatureHandler.getInstance().getKuehnSig();
     this.setEnabled();
 }
        protected internal string SignDocumentWithImage(string rootPath,
                                                        string fileName,
                                                        Stream imageStream,
                                                        int pageNumber,
                                                        int left,
                                                        int top,
                                                        int width,
                                                        int height,
                                                        int signatureColumnNum, int signatureRowNum)
        {
            string storagePath = rootPath;
            string outputPath  = Path.Combine(rootPath, @"Output");
            string imagesPath  = Path.Combine(rootPath, @"Images");

            // set up a configuration
            SignatureConfig config = new SignatureConfig()
            {
                StoragePath = storagePath,
                OutputPath  = outputPath,
                ImagesPath  = imagesPath
            };

            // instantiating the handler
            SignatureHandler handler = new SignatureHandler(config);

            // Set a license if you have one
            _licensing.ApplyLicense();

            // setup PDF image signature options
            SignImageOptions signOptions       = null;
            string           fileNameExtension = Path.GetExtension(fileName).TrimStart('.');

            fileNameExtension = fileNameExtension.ToLower();
            int pageWidth = 0, pageHeight = 0;
            DocumentViewType fileType = GetDocumentType(fileNameExtension);

            switch (fileType)
            {
            case DocumentViewType.Pdf:
                signOptions = new PdfSignImageOptions(imageStream);
                break;

            case DocumentViewType.Words:
                signOptions = new WordsSignImageOptions(imageStream);
                break;

            case DocumentViewType.Cells:
                signOptions = new CellsSignImageOptions(imageStream)
                {
                    ColumnNumber = signatureColumnNum,
                    RowNumber    = signatureRowNum
                };
                break;

            case DocumentViewType.Slides:
                signOptions = new SlidesSignImageOptions(imageStream);
                break;
            }
            signOptions.DocumentPageNumber = pageNumber;
            signOptions.Left         = left;
            signOptions.Top          = top;
            signOptions.Width        = width;
            signOptions.Height       = height;
            signOptions.SignAllPages = false;

            GroupDocs.Signature.Options.SaveOptions saveOptions = new GroupDocs.Signature.Options.SaveOptions(OutputType.String);
            // sign the document
            string outputFilePath = handler.Sign <string>(fileName, signOptions, saveOptions);

            return(outputFilePath);
        }
        static void Main(string[] args)
        {
            string rootPath    = Path.GetFullPath(@"..\..\");
            string storagePath = Path.Combine(rootPath, @"Storage");
            string outputPath  = Path.Combine(rootPath, @"Output");
            string imagesPath  = Path.Combine(rootPath, @"Images");

            // setup a configuration
            SignatureConfig config = new SignatureConfig()
            {
                StoragePath = storagePath,
                OutputPath  = outputPath,
                ImagesPath  = imagesPath
            };

            // instantiating the handler
            SignatureHandler handler = new SignatureHandler(config);

            // setup Words image signature options
            SlidesSignTextOptions options = new SlidesSignTextOptions(@"Test signature");

            // setup coordinates of image
            options.Left   = 500;
            options.Top    = 100;
            options.Width  = 100;
            options.Height = 50;

            // setup document page number
            options.DocumentPageNumber = 0;
            options.SignAllPages       = true;

            // Set a license if you have one
            License license = new License();

            license.SetLicense(@"GroupDocs.Signature3.lic");

            SaveOptions saveOptions = new SaveOptions(OutputType.String);
            string      fileName;

            using (Stream fileStream = File.OpenRead(Path.Combine(storagePath, "GroupDocs_Demo_2_pages.pptx")))
            {
                fileName = handler.Sign <string>(fileStream, options, saveOptions);
            }
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);

            // sign the document
            fileName = handler.Sign <string>(@"GroupDocs_Demo_2_pages.pptx", options, saveOptions);
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);

            LoadOptions loadOptions = new LoadOptions();

            fileName = handler.Sign <string>(@"GroupDocs_Demo_2_pages.pptx", options, loadOptions, saveOptions);
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);

            loadOptions.Password = "******";
            fileName             = handler.Sign <string>(@"GroupDocs_Demo_2_pagesPassword123.pptx", options, loadOptions, saveOptions);
            Console.WriteLine("Document signed successfully. The output filename: {0}", fileName);
            saveOptions = new SaveOptions(OutputType.Stream);
            using (Stream stream = handler.Sign <Stream>(@"GroupDocs_Demo_2_pages.pptx", options, loadOptions, saveOptions))
            {
                stream.Seek(0, SeekOrigin.Begin);
            }
        }
        /// <summary>
        /// Saves the output/signed file with document save options
        /// </summary>
        /// <param name="fileExtension">Extension of the file</param>
        /// <param name="fileName">Name of the file</param>
        /// <param name="handler">Signature's handler</param>
        /// <param name="textSignOptions">Text sign true or false</param>
        /// <param name="imageSignOptions">Image sign true or false</param>
        /// <param name="digitalSignOptions">Digital sign true or false</param>
        public static void SaveFileWithFormat(string fileExtension, string fileName, SignatureHandler handler, object textSignOptions, object imageSignOptions, object digitalSignOptions)
        {
            //ExStart:SaveFileWithFormat
            try
            {
                switch (fileExtension)
                {
                case ".docx":
                    if (textSignOptions != null)
                    {
                        //ExStart:signingworddocwithtextandsaveformatoption
                        WordsSignTextOptions wordTextSignOptions = (WordsSignTextOptions)textSignOptions;
                        var wordTextSignedPath = handler.Sign <string>(fileName, wordTextSignOptions, new WordsSaveOptions {
                            OutputType = OutputType.String, FileFormat = Domain.WordsSaveFileFormat.Pdf
                        });
                        //ExEnd:signingworddocwithtextandsaveformatoption
                    }
                    else if (textSignOptions == null && imageSignOptions != null)
                    {
                        //ExStart:signingworddocwithimageandsaveformatoption
                        WordsSignImageOptions wordImageSignOptions = (WordsSignImageOptions)imageSignOptions;
                        var wordImageSignedPath = handler.Sign <string>(fileName, wordImageSignOptions, new WordsSaveOptions {
                            OutputType = OutputType.String, FileFormat = Domain.WordsSaveFileFormat.Dot
                        });
                        //ExEnd:signingworddocwithimageandsaveformatoption
                    }
                    else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
                    {
                        //ExStart:signingworddocwithdigitalcertificatesandsaveformatoption
                        WordsSignDigitalOptions wordDigitalSignOptions = (WordsSignDigitalOptions)digitalSignOptions;
                        var wordDigitalSignedPath = handler.Sign <string>(fileName, wordDigitalSignOptions, new WordsSaveOptions {
                            OutputType = OutputType.String, FileFormat = Domain.WordsSaveFileFormat.Dotm
                        });
                        //ExEnd:signingworddocwithdigitalcertificatesandsaveformatoption
                    }

                    break;

                case ".pdf":
                    if (textSignOptions != null)
                    {
                        //ExStart:signingpdfdocwithtextandsaveformatoption
                        PdfSignTextOptions pdfTextSignOptions = (PdfSignTextOptions)textSignOptions;
                        var pdfTextSignedPath = handler.Sign <string>(fileName, pdfTextSignOptions, new PdfSaveOptions {
                            OutputType = OutputType.String, FileFormat = Domain.PdfSaveFileFormat.Doc
                        });
                        //ExEnd:signingpdfdocwithtextandsaveformatoption
                    }
                    else if (textSignOptions == null && imageSignOptions != null)
                    {
                        //ExStart:signingpdfdocwithimageandsaveformatoption
                        PdfSignImageOptions pdfImageSignOptions = (PdfSignImageOptions)imageSignOptions;
                        var pdfImageSignedPath = handler.Sign <string>(fileName, pdfImageSignOptions, new PdfSaveOptions {
                            OutputType = OutputType.String, FileFormat = Domain.PdfSaveFileFormat.Doc
                        });
                        //ExEnd:signingpdfdocwithimageandsaveformatoption
                    }
                    else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
                    {
                        //ExStart:signingpdfdocwithdigitalcertificatesandsaveformatoption
                        PdfSignDigitalOptions pdfDigitalSignOptions = (PdfSignDigitalOptions)digitalSignOptions;
                        var pdfDigitalSignedPath = handler.Sign <string>(fileName, pdfDigitalSignOptions, new PdfSaveOptions {
                            OutputType = OutputType.String, FileFormat = Domain.PdfSaveFileFormat.Pdf
                        });
                        //ExEnd:signingpdfdocwithdigitalcertificatesandsaveformatoption
                    }

                    break;

                case ".xlsx":
                    if (textSignOptions != null)
                    {
                        //ExStart:signingexceldocwithtextandsaveformatoption
                        CellsSignTextOptions cellTextSignOptions = (CellsSignTextOptions)textSignOptions;
                        var cellTextSignedPath = handler.Sign <string>(fileName, cellTextSignOptions, new CellsSaveOptions {
                            OutputType = OutputType.String, FileFormat = Domain.CellsSaveFileFormat.Xlsm
                        });
                        //ExEnd:signingexceldocwithtextandsaveformatoption
                    }
                    else if (textSignOptions == null && imageSignOptions != null)
                    {
                        //ExStart:signingexceldocwithimageandsaveformatoption
                        CellsSignImageOptions cellImageSignOptions = (CellsSignImageOptions)imageSignOptions;
                        var cellImageSignedPath = handler.Sign <string>(fileName, cellImageSignOptions, new CellsSaveOptions {
                            OutputType = OutputType.String, FileFormat = Domain.CellsSaveFileFormat.Xlsm
                        });
                        //ExEnd:signingexceldocwithimageandsaveformatoption
                    }
                    else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
                    {
                        //ExStart:signingexceldocwithdigitalcertificatesandsaveformatoption
                        CellsSignDigitalOptions cellDigitalSignOptions = (CellsSignDigitalOptions)digitalSignOptions;
                        var cellDigitalSignedPath = handler.Sign <string>(fileName, cellDigitalSignOptions, new CellsSaveOptions {
                            OutputType = OutputType.String, FileFormat = Domain.CellsSaveFileFormat.Xlsm
                        });
                        //ExEnd:signingexceldocwithdigitalcertificatesandsaveformatoption
                    }

                    break;

                case ".pptx":
                    if (textSignOptions != null)
                    {
                        //ExStart:signingslidesdocwithtextandsaveformatoption
                        SlidesSignTextOptions slildeTextSignOptions = (SlidesSignTextOptions)textSignOptions;
                        var slideTextSignedPath = handler.Sign <string>(fileName, slildeTextSignOptions, new SlidesSaveOptions {
                            OutputType = OutputType.String, FileFormat = Domain.SlidesSaveFileFormat.Odp
                        });
                        //ExEnd:signingslidesdocwithtextandsaveformatoption
                    }
                    else if (textSignOptions == null && imageSignOptions != null)
                    {
                        //ExStart:signingslidesdocwithimageandsaveformatoption
                        SlidesSignImageOptions slideImageSignOptions = (SlidesSignImageOptions)imageSignOptions;
                        var slideImageSignedPath = handler.Sign <string>(fileName, slideImageSignOptions, new SlidesSaveOptions {
                            OutputType = OutputType.String, FileFormat = Domain.SlidesSaveFileFormat.Odp
                        });
                        //ExEnd:signingslidesdocwithimageandsaveformatoption
                    }
                    else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
                    {
                        //ExStart:signingslidesdocwithdigitalcertificatesandsaveformatoption
                        SlidesSignDigitalOptions slideDigitalSignOptions = (SlidesSignDigitalOptions)digitalSignOptions;
                        var slideDigitalSignedPath = handler.Sign <string>(fileName, slideDigitalSignOptions, new SlidesSaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingslidesdocwithdigitalcertificatesandsaveformatoption
                    }

                    break;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            //ExEnd:SaveFileWithFormat
        }
        /// <summary>
        /// Saves the output/signed file
        /// </summary>
        /// <param name="fileExtension">Extension of the file</param>
        /// <param name="fileName">Name of the file</param>
        /// <param name="handler">Signature's handler</param>
        /// <param name="textSignOptions">Text sign true or false</param>
        /// <param name="imageSignOptions">Image sign true or false</param>
        /// <param name="digitalSignOptions">Digital sign true or false</param>
        public static void SaveFile(string fileExtension, string fileName, SignatureHandler handler, object textSignOptions, object imageSignOptions, object digitalSignOptions)
        {
            //ExStart:saveoutputfile
            try
            {
                switch (fileExtension)
                {
                case ".docx":
                    if (textSignOptions != null)
                    {
                        //ExStart:signingworddocwithtext
                        WordsSignTextOptions wordTextSignOptions = (WordsSignTextOptions)textSignOptions;
                        var wordTextSignedPath = handler.Sign <string>(fileName, wordTextSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingworddocwithtext
                    }
                    else if (textSignOptions == null && imageSignOptions != null)
                    {
                        //ExStart:signingworddocwithimage
                        WordsSignImageOptions wordImageSignOptions = (WordsSignImageOptions)imageSignOptions;
                        var wordImageSignedPath = handler.Sign <string>(fileName, wordImageSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingworddocwithimage
                    }
                    else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
                    {
                        //ExStart:signingworddocwithdigitalcertificates
                        WordsSignDigitalOptions wordDigitalSignOptions = (WordsSignDigitalOptions)digitalSignOptions;
                        var wordDigitalSignedPath = handler.Sign <string>(fileName, wordDigitalSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingworddocwithdigitalcertificates
                    }

                    break;

                case ".pdf":
                    if (textSignOptions != null)
                    {
                        //ExStart:signingpdfdocwithtext
                        PdfSignTextOptions pdfTextSignOptions = (PdfSignTextOptions)textSignOptions;
                        var pdfTextSignedPath = handler.Sign <string>(fileName, pdfTextSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingpdfdocwithtext
                    }
                    else if (textSignOptions == null && imageSignOptions != null)
                    {
                        //ExStart:signingpdfdocwithimage
                        PdfSignImageOptions pdfImageSignOptions = (PdfSignImageOptions)imageSignOptions;
                        var pdfImageSignedPath = handler.Sign <string>(fileName, pdfImageSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingpdfdocwithimage
                    }
                    else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
                    {
                        //ExStart:signingpdfdocwithdigitalcertificates
                        PdfSignDigitalOptions pdfDigitalSignOptions = (PdfSignDigitalOptions)digitalSignOptions;
                        var pdfDigitalSignedPath = handler.Sign <string>(fileName, pdfDigitalSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingpdfdocwithdigitalcertificates
                    }

                    break;

                case ".xlsx":
                    if (textSignOptions != null)
                    {
                        //ExStart:signingexceldocwithtext
                        CellsSignTextOptions cellTextSignOptions = (CellsSignTextOptions)textSignOptions;
                        var cellTextSignedPath = handler.Sign <string>(fileName, cellTextSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingexceldocwithtext
                    }
                    else if (textSignOptions == null && imageSignOptions != null)
                    {
                        //ExStart:signingexceldocwithimage
                        CellsSignImageOptions cellImageSignOptions = (CellsSignImageOptions)imageSignOptions;
                        var cellImageSignedPath = handler.Sign <string>(fileName, cellImageSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingexceldocwithimage
                    }
                    else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
                    {
                        //ExStart:signingexceldocwithdigitalcertificates
                        CellsSignDigitalOptions cellDigitalSignOptions = (CellsSignDigitalOptions)digitalSignOptions;
                        var cellDigitalSignedPath = handler.Sign <string>(fileName, cellDigitalSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingexceldocwithdigitalcertificates
                    }

                    break;

                case ".pptx":
                    if (textSignOptions != null)
                    {
                        //ExStart:signingslidesdocwithtext
                        SlidesSignTextOptions slildeTextSignOptions = (SlidesSignTextOptions)textSignOptions;
                        var slideTextSignedPath = handler.Sign <string>(fileName, slildeTextSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingslidesdocwithtext
                    }
                    else if (textSignOptions == null && imageSignOptions != null)
                    {
                        //ExStart:signingslidesdocwithimage
                        SlidesSignImageOptions slideImageSignOptions = (SlidesSignImageOptions)imageSignOptions;
                        var slideImageSignedPath = handler.Sign <string>(fileName, slideImageSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingslidesdocwithimage
                    }
                    else if (textSignOptions == null && imageSignOptions == null && digitalSignOptions != null)
                    {
                        //ExStart:signingslidesdocwithdigitalcertificates
                        SlidesSignDigitalOptions slideDigitalSignOptions = (SlidesSignDigitalOptions)digitalSignOptions;
                        var slideDigitalSignedPath = handler.Sign <string>(fileName, slideDigitalSignOptions, new SaveOptions {
                            OutputType = OutputType.String
                        });
                        //ExEnd:signingslidesdocwithdigitalcertificates
                    }

                    break;
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            //ExEnd:saveoutputfile
        }