public ActionResult Index(Models.PadesSignatureModel model) { // 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 = 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 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)); 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(Models.PadesSignatureModel model) { // 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 = model.Token }; // Call the FinishAsync() 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, ".pdf"); } return(View("SignatureInfo", new SignatureInfoModel() { File = fileId, SignerCertificate = signerCert })); }
public ActionResult Index(Models.PadesSignatureModel model) { // Get an instance of the PadesSignatureFinisher class, responsible for completing the signature process var signatureFinisher = Util.GetRestPkiClient().GetPadesSignatureFinisher(); // 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 signedPdf = 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 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"; System.IO.File.WriteAllBytes(Path.Combine(appDataPath, filename), signedPdf); 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 })); }