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 :)