如何从证书存储中获取X509Certificate并生成xml签名数据?

时间:2011-06-10 09:57:31

标签: c# .net xml x509certificate xml-signature

如何从证书存储区获取X509Certificate,然后在.net C#中生成XML SignatureData?

1 个答案:

答案 0 :(得分:38)

AFAIK,XML格式不保存证书,您应该自己组合。

这是你想要的吗?

   static void Main(string[] args)
    {
        X509Certificate2 cer = new X509Certificate2();
        cer.Import(@"D:\l.cer");
        X509Store store = new X509Store(StoreLocation.CurrentUser);
        store.Certificates.Add(cer);

        store.Open(OpenFlags.ReadOnly);
        X509Certificate2Collection cers = store.Certificates.Find(X509FindType.FindBySubjectName, "My Cert's Subject Name", false);
        if (cers.Count>0)
        {
            cer = cers[0];
        };
        store.Close();
    }