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"); }
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); }
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"); }
public async Task <ActionResult> Complete(string id) { // 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 = 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, ".pdf"); } // 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)); }
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(); }
public async Task <ActionResult> Complete(SignatureCompleteModel model) { string fileId; PKCertificate signerCert; try { // 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, // Set the signature computed (rendered in a hidden input field, see the view). Signature = model.Signature }; // 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. 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. using (var resultStream = result.OpenRead()) { fileId = StorageMock.Store(resultStream, ".pdf"); } // If you prefer a simpler approach without stream, simply do: //fileId = StorageMock.Store(result.GetContent(), ".pdf"); } catch (ValidationException ex) { // Return to Index view rendering the error message. ModelState.AddModelError("", ex.Message); return(View()); } // Render the signature infomation return(View("SignatureInfo", new SignatureInfoModel() { File = fileId, SignerCertificate = signerCert })); }
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 async Task <SignatureCompleteResponse> Complete(string token) { var storage = new Storage(hostingEnvironment); var client = Util.GetRestPkiClient(restPkiConfig); // Get an instance of the PadesSignatureFinisher2 class, responsible for completing the signature process var signatureFinisher = new PadesSignatureFinisher2(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 PDF on a database or storage service. For demonstration purposes, we'll // store the PDF on our "storage mock", which in turn stores the PDF 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, ".pdf"); } // 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); }
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)); }
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"); }
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 })); }
private async void signButtonClick(object sender, RoutedEventArgs e) { //var progressDialog = await this.ShowProgressAsync("Please wait...", "Signing"); Pkcs11CertificateStore p11Store = null; addLog($"Signature process begin"); progressBar.Value = 10; try { var signatureStarter = new PadesSignatureStarter(restPkiClient) { // Set the unit of measurement used to edit the pdf marks and visual representations MeasurementUnits = PadesMeasurementUnits.Centimeters, // Set the signature policy SignaturePolicyId = StandardPadesSignaturePolicies.Basic, // Set a SecurityContext to be used to determine trust in the certificate chain SecurityContextId = Guid.Parse("803517ad-3bbc-4169-b085-60053a8f6dbf"), //SecurityContextId =StandardSecurityContexts.PkiBrazil, // Note: this SecurityContext above accept unsecured certificates. You can create custom security context on the Rest PKI website. // Set a visual representation for the signature VisualRepresentation = createVisualRepresentation() }; progressBar.Value = 15; // If the user was redirected here by UploadController (signature with file uploaded by user), the "userfile" URL argument // will contain the filename under the "App_Data" folder. Otherwise (signature with server file), we'll sign a sample // document. if (string.IsNullOrEmpty(FileToSign)) { // Set the PDF to be signed as a byte array signatureStarter.SetPdfToSign(Signer.Resources.SampleDocument); } else { // Set the path of the file to be signed addLog($"file size {(new FileInfo(FileToSign).Length / 1024.0).ToString("0.00")} KBytes"); signatureStarter.SetPdfToSign(FileToSign); } /* * Optionally, add marks to the PDF before signing. These differ from the signature visual representation in that * they are actually changes done to the document prior to signing, not binded to any signature. Therefore, any number * of marks can be added, for instance one per page, whereas there can only be one visual representation per signature. * However, since the marks are in reality changes to the PDF, they can only be added to documents which have no previous * signatures, otherwise such signatures would be made invalid by the changes to the document (see property * PadesSignatureStarter.BypassMarksIfSigned). This problem does not occurr with signature visual representations. * * We have encapsulated this code in a method to include several possibilities depending on the argument passed. * Experiment changing the argument to see different examples of PDF marks. Once you decide which is best for your case, * you can place the code directly here. */ signatureStarter.PdfMarks.Add(PadesVisualElements.GetPdfMark(1)); // Call the StartWithWebPki() method, which initiates the signature. This yields the token, a 43-character // case-sensitive URL-safe string, which identifies this signature process. We'll use this value to call the // signWithRestPki() method on the Web PKI component (see javascript on the view) and also to complete the signature // on the POST action below (this should not be mistaken with the API access token). // Find selected certificate with key // -------------------------------------------------------------- PKCertificateWithKey certWithKey = null; var selectedThumbprint = (CertificatesCB.SelectedItem as ComboCertificate).Certificate.ThumbprintSHA256; p11Store = Pkcs11CertificateStore.Load(getPkcs11Modules(), new P11LoginProvider()); // search on pkcs11 store if (findCertificate(p11Store.GetCertificatesWithKey(), selectedThumbprint, out certWithKey)) { } else if (findCertificate(WindowsCertificateStore.LoadPersonalCurrentUser().GetCertificatesWithKey(), selectedThumbprint, out certWithKey)) { } else { throw new Exception("Selected certificate not found"); } // -------------------------------------------------------------- signatureStarter.SetSignerCertificate(certWithKey.Certificate.EncodedValue); progressBar.Value = 30; addLog($"Step 1: Start Signature"); var sw = Stopwatch.StartNew(); Token = await signatureStarter.StartAsync(); sw.Stop(); addLog($"Step 1: Signature Started, elapsed {sw.Elapsed.TotalSeconds:N1}s"); progressBar.Value = 50; addLog($"Signing with {certWithKey.Certificate.SubjectDisplayName}"); var signature = certWithKey.SignData(Lacuna.Pki.DigestAlgorithm.GetInstanceByOid(Token.DigestAlgorithmOid), Token.ToSignData); addLog($"Signed"); progressBar.Value = 70; var signatureFinisher = new PadesSignatureFinisher2(restPkiClient) { Token = Token.Token, Signature = signature }; sw = Stopwatch.StartNew(); // Call the Finish() method, which finalizes the signature process and returns a SignatureResult object addLog($"Step 2: Finish Signature"); var signatureResult = await signatureFinisher.FinishAsync(); sw.Stop(); addLog($"Step 2: Signature Finished, elapsed {sw.Elapsed.TotalSeconds:N1}s"); SignedFile = System.IO.Path.Combine(Path.GetDirectoryName(FileToSign), Path.GetFileNameWithoutExtension(FileToSign) + "-signed" + Path.GetExtension(FileToSign)); signatureResult.WriteToFile(SignedFile); //BusyIndicator.IsBusy = false; progressBar.Value = 100; OpenFileSignedBt.IsEnabled = true; addLog($"File signed: {SignedFile}"); } catch (Exception ex) { addLog(ex.ToString()); } finally { if (p11Store != null) { p11Store.Dispose(); } } progressBar.Value = 0; }
private async void signButtonClick(object sender, RoutedEventArgs e) { var progressDialog = await this.ShowProgressAsync("Please wait...", "Signing"); addLog($"Signature started"); progressDialog.SetProgress(0.10); try { var signatureStarter = new PadesSignatureStarter(restPkiClient) { // Set the unit of measurement used to edit the pdf marks and visual representations MeasurementUnits = PadesMeasurementUnits.Centimeters, // Set the signature policy SignaturePolicyId = StandardPadesSignaturePolicies.Basic, // Set a SecurityContext to be used to determine trust in the certificate chain SecurityContextId = Guid.Parse("803517ad-3bbc-4169-b085-60053a8f6dbf"), //SecurityContextId =StandardSecurityContexts.PkiBrazil, // Note: this SecurityContext above accept unsecured certificates. You can create custom security context on the Rest PKI website. // Set a visual representation for the signature VisualRepresentation = new PadesVisualRepresentation() { // The tags {{name}} and {{national_id}} will be substituted according to the user's certificate // // name : full name of the signer // national_id : if the certificate is ICP-Brasil, contains the signer's CPF // // For a full list of the supported tags, see: https://github.com/LacunaSoftware/RestPkiSamples/blob/master/PadesTags.md Text = new PadesVisualText("Signed by {{name}} ({{national_id}})") { // Specify that the signing time should also be rendered IncludeSigningTime = true, // Optionally set the horizontal alignment of the text ('Left' or 'Right'), if not set the default is Left HorizontalAlign = PadesTextHorizontalAlign.Left }, // We'll use as background the image in Content/PdfStamp.png Image = new PadesVisualImage(Signer.Resources.PdfStamp_png, "image/png") { // Opacity is an integer from 0 to 100 (0 is completely transparent, 100 is completely opaque). Opacity = 50, // Align the image to the right HorizontalAlign = PadesHorizontalAlign.Right }, // Position of the visual representation. We have encapsulated this code in a method to include several // possibilities depending on the argument passed. Experiment changing the argument to see different examples // of signature positioning. Once you decide which is best for your case, you can place the code directly here. Position = PadesVisualElements.GetVisualPositioning(restPkiClient, 1) }, }; var cert = CertificatesCB.SelectedItem as Cert; var certificate = getCertificate(cert.Thumbprint); signatureStarter.SetSignerCertificate(certificate.GetRawCertData()); progressDialog.SetProgress(0.15); // If the user was redirected here by UploadController (signature with file uploaded by user), the "userfile" URL argument // will contain the filename under the "App_Data" folder. Otherwise (signature with server file), we'll sign a sample // document. if (string.IsNullOrEmpty(FileToSign)) { // Set the PDF to be signed as a byte array signatureStarter.SetPdfToSign(Signer.Resources.SampleDocument); } else { // Set the path of the file to be signed addLog($"file size {new FileInfo(FileToSign).Length / 1024}kBytes"); signatureStarter.SetPdfToSign(FileToSign); } /* * Optionally, add marks to the PDF before signing. These differ from the signature visual representation in that * they are actually changes done to the document prior to signing, not binded to any signature. Therefore, any number * of marks can be added, for instance one per page, whereas there can only be one visual representation per signature. * However, since the marks are in reality changes to the PDF, they can only be added to documents which have no previous * signatures, otherwise such signatures would be made invalid by the changes to the document (see property * PadesSignatureStarter.BypassMarksIfSigned). This problem does not occurr with signature visual representations. * * We have encapsulated this code in a method to include several possibilities depending on the argument passed. * Experiment changing the argument to see different examples of PDF marks. Once you decide which is best for your case, * you can place the code directly here. */ signatureStarter.PdfMarks.Add(PadesVisualElements.GetPdfMark(1)); // Call the StartWithWebPki() method, which initiates the signature. This yields the token, a 43-character // case-sensitive URL-safe string, which identifies this signature process. We'll use this value to call the // signWithRestPki() method on the Web PKI component (see javascript on the view) and also to complete the signature // on the POST action below (this should not be mistaken with the API access token). progressDialog.SetProgress(0.20); addLog($"Step One Started"); var sw = new Stopwatch(); sw.Start(); Token = await signatureStarter.StartAsync(); sw.Stop(); addLog($"Step One finished,elapsed {sw.Elapsed.TotalSeconds:N1}s"); progressDialog.SetProgress(0.40); byte[] signature; using (RSA rsa = certificate.GetRSAPrivateKey()) { HashAlgorithmName hashAlgorithm; switch (Token.DigestAlgorithm.ApiModel) { case DigestAlgorithms.MD5: hashAlgorithm = HashAlgorithmName.MD5; break; case DigestAlgorithms.SHA1: hashAlgorithm = HashAlgorithmName.SHA1; break; case DigestAlgorithms.SHA256: hashAlgorithm = HashAlgorithmName.SHA256; break; case DigestAlgorithms.SHA384: hashAlgorithm = HashAlgorithmName.SHA384; break; case DigestAlgorithms.SHA512: hashAlgorithm = HashAlgorithmName.SHA512; break; default: throw new ArgumentOutOfRangeException(); } signature = rsa.SignData(Token.ToSignData, hashAlgorithm, RSASignaturePadding.Pkcs1); var signatureFinisher = new PadesSignatureFinisher2(restPkiClient) { Token = Token.Token, Signature = signature }; progressDialog.SetProgress(0.50); // Call the Finish() method, which finalizes the signature process and returns a SignatureResult object sw.Reset(); sw.Start(); var signatureResult = await signatureFinisher.FinishAsync(); sw.Stop(); addLog($"Step two finished,elapsed {sw.Elapsed.TotalSeconds:N1}s"); SignedFile = System.IO.Path.Combine(Path.GetDirectoryName(FileToSign), Path.GetFileNameWithoutExtension(FileToSign) + "Signed" + Path.GetExtension(FileToSign)); signatureResult.WriteToFile(SignedFile); //BusyIndicator.IsBusy = false; progressDialog.SetProgress(0.99); OpenFileSignedBt.IsEnabled = true; addLog($"Signarure finished"); } } catch (Exception ex) { addLog(ex.ToString()); } await progressDialog.CloseAsync(); }