Esempio n. 1
0
        protected void seal_Click(object sender, EventArgs e)
        {
            DsspClient dsspClient = new DsspClient("https://www.e-contract.be/dss-ws/dss");

            dsspClient.Application.X509.Certificate = new X509Certificate2(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, @"App_Data\certificate.p12"), "");

            Document sealedDocument = dsspClient.Seal((Document)Session["signedDocument"]);

            Session["signedDocument"] = sealedDocument;
        }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Document document = new Document();

            document.MimeType = "application/pdf";
            document.Content  = File.OpenRead(Path.Combine(HostingEnvironment.ApplicationPhysicalPath, @"App_Data\dssp-specs.pdf"));

            DsspClient dsspClient = new DsspClient("https://www.e-contract.be/dss-ws/dss");

            dsspClient.ApplicationName     = Settings.Default.AppName;
            dsspClient.ApplicationPassword = Settings.Default.AppPwd;
            DsspSession dsspSession = dsspClient.UploadDocument(document);

            Session["dsspSession"] = dsspSession;

            VisibleSignatureProperties visibleSignature = null;

            if ((String)Session["Visible"] == "Photo")
            {
                visibleSignature = new ImageVisibleSignature()
                {
                    Page = (int)Session["Page"],
                    X    = (int)Session["X"],
                    Y    = (int)Session["Y"]
                };
            }
            else if ((String)Session["Visible"] == "Photo and Signer Info")
            {
                visibleSignature = new ImageVisibleSignature()
                {
                    Page       = (int)Session["Page"],
                    X          = (int)Session["X"],
                    Y          = (int)Session["Y"],
                    ValueUri   = "urn:be:e-contract:dssp:1.0:vs:si:eid-photo:signer-info",
                    CustomText = (string)Session["CustomText"]
                };
            }

            // verify whether DsspSession is serializable
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            MemoryStream    memoryStream    = new MemoryStream();

            binaryFormatter.Serialize(memoryStream, dsspSession);
            memoryStream.Seek(0, SeekOrigin.Begin);
            dsspSession = (DsspSession)binaryFormatter.Deserialize(memoryStream);

            Authorization authorization = new Authorization();

            //authorization.AddAuthorizedCardNumber("591591588049");
            //authorization.AddAuthorizedSubjectName("SERIALNUMBER=79102520991, GIVENNAME=Frank Henri, SURNAME=Cornelis, CN=Frank Cornelis (Signature), C=BE");
            //authorization.AddNonAuthorizedSubjectName("SERIALNUMBER=79102520991, GIVENNAME=Frank Henri, SURNAME=Cornelis, CN=Frank Cornelis (Signature), C=BE");

            this.PendingRequest.Value = dsspSession.GeneratePendingRequest(
                new Uri(Request.Url, ResolveUrl("~/Signed.aspx")),
                Settings.Default.Language,
                new SignatureRequestProperties()
            {
                SignerRole = (string)Session["Role"],
                SignatureProductionPlace = (string)Session["Location"],
                VisibleSignature         = visibleSignature
            },
                authorization
                );
        }