Example #1
0
        public ActionResult Index(CadesSignatureModel model)
        {
            // Get an instance of the PadesSignatureFinisher class, responsible for completing the signature process
            var signatureFinisher = new CadesSignatureFinisher(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 CMS
            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 signerCert = signatureFinisher.GetCertificateInfo();

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

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

            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 ActionResult Index(CadesSignatureModel model)
        {
            // Get an instance of the PadesSignatureFinisher class, responsible for completing the signature process
            var signatureFinisher = new CadesSignatureFinisher(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 CMS
            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 signerCert = signatureFinisher.GetCertificateInfo();

            // 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";
            System.IO.File.WriteAllBytes(Path.Combine(appDataPath, filename), cms);

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