How to get X509Certificate from certificate store and generate xml signature data?

岁酱吖の 提交于 2019-11-27 23:14:51

问题


How can I get X509Certificate from certificate store and then generate XML SignatureData in .net C#?


回答1:


As far as I know, certificates are not saved by XML Format , you should combine it by yourself.

Is this what you want ?

   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();
   }


来源:https://stackoverflow.com/questions/6304773/how-to-get-x509certificate-from-certificate-store-and-generate-xml-signature-dat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!