Ejemplo n.º 1
0
        public static string Complete(string token)
        {
            // Get an instance of the PadesSignatureFinisher2 class, responsible for completing the signature process
            var signatureFinisher = new PadesSignatureFinisher2(Util.GetRestPkiClient())
            {
                // Set the token for this signature acquired previously
                Token = token
            };

            // Call the Finish() method, which finalizes the signature process and returns an SignatureResult object to access
            // the signed PDF
            var result = signatureFinisher.Finish();

            // At this point, you'd typically store the signed PDF on your database. For demonstration purposes, we'll
            // store the PDF on our mock Storage class.

            // The SignatureResult object has various methods for writing the signature file to a stream (WriteTo()), local file (WriteToFile()), open
            // a stream to read the content (OpenRead()) and get its contents (GetContent()). For large files, avoid the method GetContent() to avoid
            // memory allocation issues.
            string fileId;

            using (var resultStream = result.OpenRead()) {
                fileId = StorageMock.Store(resultStream, ".pdf");
            }
            // If you prefer a simpler approach without streams, simply do:
            //fileId = StorageMock.Store(result.GetContent(), ".pdf");

            // Send to the javascript the signed file's id to be referenced on a download link
            return(fileId);
        }
Ejemplo n.º 2
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            // Get an instance of the PadesSignatureFinisher2 class, responsible for completing the signature process
            var signatureFinisher = new PadesSignatureFinisher2(Util.GetRestPkiClient())
            {
                // Set the token for this signature acquired previously
                Token = (string)ViewState["Token"]
            };

            // Call the Finish() method, which finalizes the signature process and returns an object to access the signed PDF
            var result = signatureFinisher.Finish();

            // At this point, you'd typically store the signed PDF on your database. For demonstration purposes, we'll
            // store the PDF on our mock Storage class.

            // The SignatureResult object has various methods for writing the signature file to a stream (WriteTo()), local file (WriteToFile()), open
            // a stream to read the content (OpenRead()) and get its contents (GetContent()). For large files, avoid the method GetContent() to avoid
            // memory allocation issues.
            string fileId;

            using (var resultStream = result.OpenRead()) {
                fileId = StorageMock.Store(resultStream, ".pdf");
            }
            // If you prefer a simpler approach without streams, simply do:
            //fileId = StorageMock.Store(result.GetContent(), ".pdf");

            // What you do at this point is up to you. For demonstration purposes, we'll render a page with a link to
            // download the signed PDF and with the signer's certificate details.
            this.SignatureFilename = fileId;
            this.SignerCertificate = result.Certificate;
            Server.Transfer("PadesSignatureInfo.aspx");
        }
Ejemplo n.º 3
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            // Get an instance of the PadesSignatureFinisher2 class, responsible for completing the signature process
            var signatureFinisher = new PadesSignatureFinisher2(Util.GetRestPkiClient())
            {
                // Set the token for this signature (rendered in a hidden input field, see the view)
                Token = (string)ViewState["Token"]
            };

            // Call the Finish() method, which finalizes the signature process and returns an object to access the signed PDF
            var result = signatureFinisher.Finish();

            // At this point, you'd typically store the signed PDF on your database. For demonstration purposes, we'll
            // store the PDF on our mock Storage class
            string fileId;

            using (var resultStream = result.OpenRead()) {
                fileId = StorageMock.Store(resultStream, ".pdf");
            }
            // If you prefer a simpler approach without streams, simply do:
            // fileId = Storage.Store(result.GetContent(), ".pdf");

            // What you do at this point is up to you. For demonstration purposes, we'll render a page with a link to
            // download the signed PDF and with the signer's certificate details.
            this.SignatureFilename = fileId;
            this.SignerCertificate = result.Certificate;
            Server.Transfer("PadesSignatureInfo.aspx");
        }
Ejemplo n.º 4
0
        private void completeSignature()
        {
            string filename;

            try {
                // Get an instance of the PadesSignatureFinisher2 class, responsible for completing the signature process
                var signatureFinisher = new PadesSignatureFinisher2(Util.GetRestPkiClient())
                {
                    // Retrieve the token for this signature stored on the initial step (see method startNextSignature())
                    Token = TokenField.Value
                };

                // Call the Finish() method, which finalizes the signature process and returns a SignatureResult object
                var signatureResult = signatureFinisher.Finish();

                // At this point, you'd typically store the signed PDF on your database. For demonstration purposes, we'll
                // store the PDF on the App_Data folder.

                var appDataPath = Server.MapPath("~/App_Data");
                if (!Directory.Exists(appDataPath))
                {
                    Directory.CreateDirectory(appDataPath);
                }
                var id = Guid.NewGuid();
                filename = id + ".pdf";

                // The SignatureResult object has various methods for writing the signature file to a stream (WriteTo()), local file (WriteToFile()), open
                // a stream to read the content (OpenRead()) and get its contents (GetContent()). For large files, avoid the method GetContent() to avoid
                // memory allocation issues.
                signatureResult.WriteToFile(Path.Combine(appDataPath, filename));
            } catch (ValidationException ex) {
                // One or more validations failed. We log the error and update the page with a summary of what happened to this document
                //logger.Error(ex, "Validation error completing the signature of a batch document");
                setValidationError(ex.ValidationResults);
                return;
            } catch (Exception ex) {
                // An error has occurred. We log the error and update the page with a summary of what happened to this document
                //logger.Error(ex, "Error completing the signature of a batch document");
                setError(ex.Message);
                return;
            }

            // Update the page with a link to the signed file
            var docItem = DocumentsListView.Items[DocumentIndex];

            docItem.DataItem = new DocumentItem()
            {
                Id           = DocumentIds[DocumentIndex],
                DownloadLink = "Download.aspx?file=" + filename
            };
            docItem.DataBind();
        }
Ejemplo n.º 5
0
        private void completeSignature()
        {
            string fileId;

            try {
                // Get an instance of the PadesSignatureFinisher2 class, responsible for completing the signature process
                var signatureFinisher = new PadesSignatureFinisher2(Util.GetRestPkiClient())
                {
                    // Retrieve the token for this signature stored as hidden field on the initial step (see method startNextSignature())
                    Token = TokenField.Value
                };

                // Call the Finish() method, which finalizes the signature process and returns an SignatureResult object to access
                // the signed PDF
                var result = signatureFinisher.Finish();

                // At this point, you'd typically store the signed PDF on your database. For demonstration purposes, we'll
                // store the PDF on our mock Storage class.


                // The SignatureResult object has various methods for writing the signature file to a stream (WriteTo()), local file (WriteToFile()), open
                // a stream to read the content (OpenRead()) and get its contents (GetContent()). For large files, avoid the method GetContent() to avoid
                // memory allocation issues.
                using (var resultStream = result.OpenRead()) {
                    fileId = StorageMock.Store(resultStream, ".pdf");
                }
                // If you prefer a simpler approach without streams, simply do:
                //fileId = StorageMock.Store(result.GetContent(), ".pdf");
            } catch (ValidationException ex) {
                // One or more validations failed. We log the error and update the page with a summary of what happened to this document
                setValidationError(ex.ValidationResults);
                return;
            } catch (Exception ex) {
                // An error has occurred. We log the error and update the page with a summary of what happened to this document
                setError(ex.Message);
                return;
            }

            // Update the page with a link to the signed file
            var docItem = DocumentsListView.Items[DocumentIndex];

            docItem.DataItem = new DocumentItem()
            {
                Id           = DocumentIds[DocumentIndex],
                DownloadLink = "Download.aspx?fileId=" + fileId
            };
            docItem.DataBind();
        }
        public ActionResult Complete(BatchSignatureCompleteRequest request)
        {
            // Get an instance of the PadesSignatureFinisher2 class, responsible for completing the signature process
            var signatureFinisher = new PadesSignatureFinisher2(Util.GetRestPkiClient())
            {
                // Set the token for this signature (rendered in a hidden input field, see the view)
                Token = request.Token,

                // Set the result of the RSA signature. Notice that this call is not necessary on the "regular" batch signature example
                Signature = Convert.FromBase64String(request.Signature),
            };

            // Call the Finish() method, which finalizes the signature process and returns a SignatureResult object
            var signatureResult = signatureFinisher.Finish();

            // The "Certificate" property of the SignatureResult object contains information about the certificate used by the user
            // to sign the file.
            var signerCert = signatureResult.Certificate;

            // At this point, you'd typically store the signed PDF on your database. For demonstration purposes, we'll
            // store the PDF on the App_Data folder and render a page with a link to download the signed PDF and with the
            // signer's certificate details.

            var appDataPath = Server.MapPath("~/App_Data");

            if (!Directory.Exists(appDataPath))
            {
                Directory.CreateDirectory(appDataPath);
            }
            var signedFileId = Guid.NewGuid();
            var filename     = signedFileId + ".pdf";

            // The SignatureResult object has various methods for writing the signature file to a stream (WriteTo()), local file (WriteToFile()), open
            // a stream to read the content (OpenRead()) and get its contents (GetContent()). For large files, avoid the method GetContent() to avoid
            // memory allocation issues.
            signatureResult.WriteToFile(Path.Combine(appDataPath, filename));

            var signedFile = filename.Replace(".", "_");             // Note: we're passing the filename argument with "." as "_" because of limitations of ASP.NET MVC

            return(Json(signedFile));
        }
Ejemplo n.º 7
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            // Get an instance of the PadesSignatureFinisher2 class, responsible for completing the signature process
            var signatureFinisher = new PadesSignatureFinisher2(Util.GetRestPkiClient())
            {
                // Set the token for this signature acquired previously
                Token = (string)ViewState["Token"]
            };

            // Call the Finish() method, which finalizes the signature process and returns a SignatureResult object
            var signatureResult = signatureFinisher.Finish();

            // The "Certificate" property of the SignatureResult object contains information about the certificate used by the user
            // to sign the file.
            var signerCert = signatureResult.Certificate;

            // At this point, you'd typically store the signed PDF on your database. For demonstration purposes, we'll
            // store the PDF on the App_Data folder and render a page with a link to download the signed PDF and with the
            // signer's certificate details.

            var appDataPath = Server.MapPath("~/App_Data");

            if (!Directory.Exists(appDataPath))
            {
                Directory.CreateDirectory(appDataPath);
            }
            var id       = Guid.NewGuid();
            var filename = id + ".pdf";

            // The SignatureResult object has various methods for writing the signature file to a stream (WriteTo()), local file (WriteToFile()), open
            // a stream to read the content (OpenRead()) and get its contents (GetContent()). For large files, avoid the method GetContent() to avoid
            // memory allocation issues.
            signatureResult.WriteToFile(Path.Combine(appDataPath, filename));

            this.SignatureFilename = filename;
            this.SignerCertificate = signerCert;
            Server.Transfer("PadesSignatureInfo.aspx");
        }