2011-06-10 86 views

回答

26

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

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

您需要調用「store.Open(OpenFlags.ReadOnly);」如果在查找之前未將證書添加到商店中,則在「查找」之前。 – aelstonjones 2013-10-09 20:12:46

+0

'''使用System.Security.Cryptography.X509Certificates'''來獲取導入的名稱空間。 – 2016-03-21 22:47:33