public ActionResult Index(XmlSignatureModel model) {

			// Get an instance of the XmlSignatureFinisher class, responsible for completing the signature process
			var signatureFinisher = new XmlSignatureFinisher(Util.GetRestPkiClient());

			// Set the token for this signature (rendered in a hidden input field, see the view)
			signatureFinisher.SetToken(model.Token);

			// Call the Finish() method, which finalizes the signature process and returns the signed PDF
			var signedXml = signatureFinisher.Finish();

			// Get information about the certificate used by the user to sign the file. This method must only be called after
			// calling the Finish() method.
			var signerCert = signatureFinisher.GetCertificateInfo();

			// At this point, you'd typically store the signed XML on your database. For demonstration purposes, we'll
			// store the XML on the App_Data folder and render a page with a link to download the signed XML 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 + ".xml";
			System.IO.File.WriteAllBytes(Path.Combine(appDataPath, filename), signedXml);

			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
			});
		}
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            // Get an instance of the XmlSignatureFinisher class, responsible for completing the signature process
            var signatureFinisher = new XmlSignatureFinisher(Util.GetRestPkiClient());

            // Set the token for this signature (rendered in a hidden input field, see the view)
            signatureFinisher.SetToken((string)ViewState["Token"]);

            // Call the Finish() method, which finalizes the signature process and returns the signed XML
            var cms = signatureFinisher.Finish();

            // Get information about the certificate used by the user to sign the file. This method must only be called after
            // calling the Finish() method.
            var signerCertificate = signatureFinisher.GetCertificateInfo();

            // At this point, you'd typically store the XML on your database. For demonstration purposes, we'll
            // store the XML 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 + ".xml";

            File.WriteAllBytes(Path.Combine(appDataPath, filename), cms);

            this.SignatureFilename = filename;
            this.SignerCertificate = signerCertificate;
            Server.Transfer("XmlElementSignatureInfo.aspx");
        }
        public async Task <ActionResult> Index(SignatureModel model)
        {
            // Get an instance of the XmlSignatureFinisher class, responsible for completing the signature
            // process.
            var signatureFinisher = new XmlSignatureFinisher(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 the signed PDF.
            var signedXml = await signatureFinisher.FinishAsync();

            // Get information about the signer's certificate used. This method must only be called after
            // calling the Finish() method.
            var signerCert = signatureFinisher.GetCertificateInfo();

            // At this point, you'd typically store the signed XML on your database. For demonstration
            // purposes, we'll store the PDF on our mock Storage class.
            var fileId = StorageMock.Store(signedXml, ".xml");

            // Render the signature information page.
            return(View("SignatureInfo", new SignatureInfoModel()
            {
                File = fileId,
                SignerCertificate = signerCert
            }));
        }
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            // Get an instance of the XmlSignatureFinisher class, responsible for completing the signature process
            var signatureFinisher = new XmlSignatureFinisher(Util.GetRestPkiClient());

            // Set the token for this signature (rendered in a hidden input field, see the view)
            signatureFinisher.SetToken((string)ViewState["Token"]);

            // Call the Finish() method, which finalizes the signature process and returns the signed XML
            var cms = signatureFinisher.Finish();

            // Get information about the certificate used by the user to sign the file. This method must only be called after
            // calling the Finish() method.
            var signerCertificate = signatureFinisher.GetCertificateInfo();

            // At this point, you'd typically store the XML on your database. For demonstration purposes, we'll
            // store the XML 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 + ".xml";
            File.WriteAllBytes(Path.Combine(appDataPath, filename), cms);

            this.SignatureFilename = filename;
            this.SignerCertificate = signerCertificate;
            Server.Transfer("XmlElementSignatureInfo.aspx");
        }
Пример #5
0
        public async Task <SignatureCompleteResponse> Complete(string token)
        {
            var storage = new Storage(hostingEnvironment);
            var client  = Util.GetRestPkiClient(restPkiConfig);

            // Get an instance of the XmlSignatureFinisher class, responsible for completing the signature process
            var signatureFinisher = new XmlSignatureFinisher(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 signedXmlBytes = 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 = signatureFinisher.GetCertificateInfo();

            // At this point, you'd typically store the signed XML on a database or storage service. For demonstration purposes, we'll
            // store the XML on our "storage mock", which in turn stores the XML 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.
            var filename = await storage.StoreAsync(signedXmlBytes, ".xml");

            // 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);
        }
Пример #6
0
        public ActionResult Index(XmlSignatureModel model)
        {
            // Get an instance of the XmlSignatureFinisher class, responsible for completing the signature process
            var signatureFinisher = new XmlSignatureFinisher(Util.GetRestPkiClient());

            // Set the token for this signature (rendered in a hidden input field, see the view)
            signatureFinisher.SetToken(model.Token);

            // Call the Finish() method, which finalizes the signature process and returns the signed PDF
            var signedXml = signatureFinisher.Finish();

            // Get information about the certificate used by the user to sign the file. This method must only be called after
            // calling the Finish() method.
            var signerCert = signatureFinisher.GetCertificateInfo();

            // At this point, you'd typically store the signed XML on your database. For demonstration purposes, we'll
            // store the XML on the App_Data folder and render a page with a link to download the signed XML 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 + ".xml";

            System.IO.File.WriteAllBytes(Path.Combine(appDataPath, filename), signedXml);

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