Ejemplo n.º 1
0
        public async Task <ActionResult> Complete(string id)
        {
            // Get an instance of the CadesSignatureFinisher2 class, responsible for completing the signature
            // process.
            var signatureFinisher = new CadesSignatureFinisher2(Util.GetRestPkiClient())
            {
                // Set the token for this signature. (rendered in a hidden input field, see the view)
                Token = id
            };

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

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

            // 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, ".p7s");
            }

            // Return a JSON with the signed file's id, stored using our mock class (the page will use
            // jQuery to decode this value).
            return(Json(fileId));
        }
Ejemplo n.º 2
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            // Get an instance of the CadesSignatureFinisher2 class, responsible for completing the signature process
            var signatureFinisher = new CadesSignatureFinisher2(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 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, ".p7s");
            }
            // 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("CadesSignatureInfo.aspx");
        }
Ejemplo n.º 3
0
        public async Task <SignatureCompleteResponse> Complete(string token)
        {
            var storage = new Storage(hostingEnvironment);
            var client  = Util.GetRestPkiClient(restPkiConfig);

            // Get an instance of the CadesSignatureFinisher2 class, responsible for completing the signature process
            var signatureFinisher = new CadesSignatureFinisher2(client)
            {
                // Set the token for this signature (acquired previously and passed back here by the angular controller)
                Token = token
            };

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

            // 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 CMS on a database or storage service. For demonstration purposes, we'll
            // store the CMS on our "storage mock", which in turn stores the CMS on the App_Data folder.

            // The SignatureResult object has various methods for writing the signature file to a stream (WriteToAsync()), local file (WriteToFileAsync()),
            // open a stream to read the content (OpenReadAsync()) and get its contents (GetContentAsync()). Avoid the method GetContentAsync() to prevent
            // memory allocation issues with large files.
            string filename;

            using (var signatureStream = await signatureResult.OpenReadAsync()) {
                filename = await storage.StoreAsync(signatureStream, ".p7s");
            }

            // Pass the following fields to be used on signature-results template:
            // - The signature filename, which can be used to provide a link to the file
            // - The user's certificate
            var response = new SignatureCompleteResponse()
            {
                Filename    = filename,
                Certificate = new Models.CertificateModel(signerCert)
            };

            return(response);
        }
Ejemplo n.º 4
0
        public ActionResult Index(CadesSignatureModel model)
        {
            // Get an instance of the CadesSignatureFinisher2 class, responsible for completing the signature process
            var signatureFinisher = new CadesSignatureFinisher2(Util.GetRestPkiClient())
            {
                // Set the token for this signature (rendered in a hidden input field, see the view)
                Token = model.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 CMS on your database. For demonstration purposes, we'll
            // store the CMS on the App_Data folder and render a page with a link to download the CMS 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 + ".p7s";

            // 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));

            return(View("SignatureInfo", new SignatureInfoModel()
            {
                File = filename.Replace(".", "_"),                 // Note: we're passing the filename argument with "." as "_" because of limitations of ASP.NET MVC
                SignerCertificate = signerCert
            }));
        }
        public async Task <ActionResult> Index(SignatureModel model)
        {
            // Get an instance of the CadesSignatureFinisher2 class, responsible for completing the signature
            // process.
            var signatureFinisher = new CadesSignatureFinisher2(Util.GetRestPkiClient())
            {
                // Set the token for this signature (rendered in a hidden input field, see the view).
                Token = model.Token
            };

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

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

            // At this point, you'd typically store the CMS 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, ".p7s");
            }

            // Render the signature information page.
            return(View("SignatureInfo", new SignatureInfoModel()
            {
                File = fileId,
                SignerCertificate = signerCert
            }));
        }
Ejemplo n.º 6
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            // Get an instance of the CadesSignatureFinisher2 class, responsible for completing the signature process
            var signatureFinisher = new CadesSignatureFinisher2(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 CMS on your database. For demonstration purposes, we'll
            // store the CMS on the App_Data folder and render a page with a link to download the CMS 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 + ".p7s";

            // 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("CadesSignatureInfo.aspx");
        }