private async void Sign_Click(object sender, RoutedEventArgs e) { X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); X509Certificate2Collection collection = store.Certificates; X509Certificate2Collection fcollection = collection.Find(X509FindType.FindByKeyUsage, X509KeyUsageFlags.NonRepudiation, true); X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(fcollection, "Sign Certificate Select", "Select a certificate to sign with", X509SelectionFlag.SingleSelection); DsspClient dsspClient = new DsspClient("https://www.e-contract.be/dss-ws/dss"); dsspClient.Application.UT.Name = Properties.Settings.Default.user; dsspClient.Application.UT.Password = Properties.Settings.Default.pwd; dsspClient.Signer = scollection.Cast <X509Certificate2>().AsQueryable().FirstOrDefault(); using (new WaitCursor()) { Dssp2StepSession dsspSession; var signProps = new SignatureRequestProperties(); signProps.SignerRole = this.Role.Text; signProps.SignatureProductionPlace = this.Location.Text; using (Stream input = File.OpenRead(FilePath.Text)) { var inDoc = new Document() { MimeType = "application/pdf", Content = input }; dsspSession = await dsspClient.UploadDocumentFor2StepAsync(inDoc, signProps); } dsspSession.Sign(); var outDoc = await dsspClient.DownloadDocumentAsync(dsspSession); using (Stream output = File.Create(FilePath.Text)) { await outDoc.Content.CopyToAsync(output); } } }
public async Task <HttpResponseMessage> Get(string id, string location, string role, string visible, int?page, int?x, int?y) { try { //get the requested document and covert it for upload. Document doc = docs[id].ToDocument(); //Upload it, keeping the DSS-P session that is returned dsspClient.ApplicationName = configuration.Current.AppName; dsspClient.ApplicationPassword = configuration.Current.AppPwd; sessions[id] = await dsspClient.UploadDocumentAsync(doc); //Create properties SignatureRequestProperties props = null; if (!configuration.Current.AltMode || visible != "None" || !string.IsNullOrEmpty(location) || !string.IsNullOrEmpty(role)) { props = new SignatureRequestProperties() { SignatureProductionPlace = location, SignerRole = role }; } if (visible == "Photo") { //Create an image visual signature, which defaults to eID photo props.VisibleSignature = new ImageVisibleSignature() { Page = page.Value, X = x.Value, Y = y.Value }; } //creating the browser post page with the pending request string browserPostPage; if (configuration.Current.AltMode) { if (string.IsNullOrEmpty(configuration.Current.Lanuage) && props == null && string.IsNullOrEmpty(configuration.Current.Authorization)) { browserPostPage = sessions[id].GeneratePendingRequestPage("https://www.e-contract.be/dss-ws/start", Request.RequestUri.ToString()); } else if (props == null && string.IsNullOrEmpty(configuration.Current.Authorization)) { browserPostPage = sessions[id].GeneratePendingRequestPage("https://www.e-contract.be/dss-ws/start", Request.RequestUri.ToString(), configuration.Current.Lanuage); } else if (string.IsNullOrEmpty(configuration.Current.Authorization) && props != null) { browserPostPage = sessions[id].GeneratePendingRequestPage(new Uri("https://www.e-contract.be/dss-ws/start"), Request.RequestUri, configuration.Current.Lanuage, props); } else if (!string.IsNullOrEmpty(configuration.Current.Authorization) && props == null) { browserPostPage = sessions[id].GeneratePendingRequestPage(new Uri("https://www.e-contract.be/dss-ws/start"), Request.RequestUri, configuration.Current.Lanuage, EContract.Dssp.Client.Authorization.AllowDssSignIfMatchSubject(configuration.Current.Authorization)); } else { browserPostPage = sessions[id].GeneratePendingRequestPage(new Uri("https://www.e-contract.be/dss-ws/start"), Request.RequestUri, configuration.Current.Lanuage, props, EContract.Dssp.Client.Authorization.AllowDssSignIfMatchSubject(configuration.Current.Authorization)); } } else { browserPostPage = sessions[id].GeneratePendingRequestPage(new Uri("https://www.e-contract.be/dss-ws/start"), Request.RequestUri, configuration.Current.Lanuage, props, configuration.Current.Authorization); } //returning it to the browser to execute HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new ByteArrayContent(Encoding.ASCII.GetBytes(browserPostPage)); result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); return(result); } catch (Exception e) { docs[id].Alert = new Alert() { Message = e.Message, Type = "danger" }; return(RedirectBack()); } }