none
Display certificate in an asp form(digital signature) RRS feed

  • Question

  • Hi everyone,

    i want to display on a web form my certificate.Is it possible? and how ?or something else?

    my project consist of a purchase order that need to be digitaly sign with a certificate 

    i'm sorry for mistake(s) but i come from belgium  ^^ 

    with that code :
     X509Store store = new X509Store(StoreLocation.CurrentUser);

                store.Open(OpenFlags.ReadOnly);
                X509CertificateCollection certificates =
        X509Certificate2UI.SelectFromCollection
        (
        store.Certificates,
        "Liste des certificats",
        "Veuillez sélectionner un certificat",
        X509SelectionFlag.SingleSelection
        );
                X509Certificate2 certificate = null;
                if (certificates.Count != 0)
                {
                    certificate = (X509Certificate2)certificates[0];
                }
                /*afficher tout
                 foreach (X509Certificate2 cert in store.Certificates)
                  {
                      Console.WriteLine(string.Format("Délivré à {0} par {1}",cert.SubjectName.Name, cert.IssuerName.Name));

                  }*/

                Console.WriteLine(string.Format("Délivré à {0} par {1}", certificate.SubjectName.Name, certificate.IssuerName.Name));


                store.Close();

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.PreserveWhitespace = true;
                xmlDoc.Load("article.xml");
                SignedXml signedXml = new SignedXml(xmlDoc);
                signedXml.SigningKey = certificate.PrivateKey;
                KeyInfo keyInfo = new KeyInfo();
                keyInfo.AddClause(new KeyInfoX509Data(certificate));
                signedXml.KeyInfo = keyInfo;
                Reference reference = new Reference();
                reference.Uri = "";
                reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
                signedXml.AddReference(reference);
                signedXml.ComputeSignature();
                XmlElement signature = signedXml.GetXml();
                xmlDoc.DocumentElement.AppendChild(xmlDoc.ImportNode(signature, true));
                xmlDoc.Save("envelopeds.xml");

                XmlDocument xmlDoc2 = new XmlDocument();
                xmlDoc2.PreserveWhitespace = true;
                xmlDoc2.Load("envelopeds.xml");
                SignedXml signedXml2 = new SignedXml(xmlDoc2);
                XmlNodeList nodeList = xmlDoc2.GetElementsByTagName("Signature");
                signedXml2.LoadXml((XmlElement)nodeList[0]);
                bool valid = signedXml2.CheckSignature();
                if (valid == true)
                {
                    Console.WriteLine("not changed");
                    textBox3.Text = certificate.ToString(true);
                    textBox4.Text = DateTime.Now.ToString();
                  //  pictureBox1.Load(certificate.ToString());
                }
                else
                {
                    Console.WriteLine("bad :(");

                }

    thanks a lot :)

    Tuesday, February 25, 2014 8:40 AM

Answers

  • Hi Deweweire,

    From your description, did you want to protect the process of purchase order and transform the purchase order to PDF for being download future? You said that the purchase order will be completed by ASP.NET web form application, I think what’s you need is to use SSL to protect the progress when sending request to server and receiving response from server.

    For more information about SSL, see the following link. http://www.macaw.nl/weblog/2013/6/configuring-an-asp-net-project-for-development-with-ssl.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 4, 2014 8:43 AM
    Moderator

All replies

  • Hi Deweweire,

    >i want to display on a web form my certificate. Is it possible? And how? Or something else?

    Did you want to show your certificate information in your ASP.NET web form? See the following link to know how to view a certificate programmatically. http://blogs.msdn.com/b/alejacma/archive/2009/02/13/how-to-view-a-certificate-programatically-c.aspx.

    I see there is code about SignedXml, did you encounter error? If so, please post here.

    If I misunderstand you, please post more information.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 26, 2014 5:04 AM
    Moderator
  • hi,

    first, thanks for reply

    my code extract a certificate and i can access all data.

    I just want to display(show) my certificate in a web form( i don't know the control and how to display the certificate).My purpose is use certificate to sign a document .This signature need to be legal because it's for a purchase order project so i don't really know if i need to show the certificate in a webform or something like that but i try to find an answer for that

    I really don't know if it's possible so i ask^^
    Wednesday, February 26, 2014 7:34 AM
  • Hi Deweweire,

    SingnedXML just need certificate to work with him, you don’t need to display certificate in a web form. But I am afraid you have misunderstanding to SingnedXML. This class is for protecting the process, preventing someone from tampering with documents during the transmission process. Per my understanding, what you want is to encrypt information about purchase order. When your customer place an order on your web site, you can encrypt them and save them into Database. And use SSL to make sure for safe http.

    The following is some useful links.

    http://www.codeproject.com/Tips/486387/Cryptography-with-certificates.

    http://www.asp.net/web-api/overview/security/working-with-ssl-in-web-api.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 28, 2014 7:11 AM
    Moderator
  • Hi,

    Thanks for this reply.I understand now :)

    What i wanted is a way to prove that the Purchase order is signed with securities When the provider will open my po is a pdf format. The purchase order will be completed by a web form .This web form will be transformed in a pdf).Do you understand?

    Sorry for mistake(s), but i come from belgium^^

    Regards,

    Friday, February 28, 2014 7:17 AM
  • Hi Deweweire,

    From your description, did you want to protect the process of purchase order and transform the purchase order to PDF for being download future? You said that the purchase order will be completed by ASP.NET web form application, I think what’s you need is to use SSL to protect the progress when sending request to server and receiving response from server.

    For more information about SSL, see the following link. http://www.macaw.nl/weblog/2013/6/configuring-an-asp-net-project-for-development-with-ssl.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 4, 2014 8:43 AM
    Moderator
  • yes i want to protect the process of purchase order and transform the purchase order to pdf for being download future :) exactly what i want
    Tuesday, March 4, 2014 8:45 AM