0

電子メールを暗号化するためにADサーバーからc#を使用してX509パブリック証明書をフェッチする方法はありますか?現在、証明書の取得とメールの暗号化にローカルストアを使用しています。

static public X509Certificate2 GetRecipientCertPublic(string recipientName)
{  
    X509Store storeAddressBook =
        new X509Store(StoreName.AddressBook, StoreLocation.CurrentUser);
    storeAddressBook.Open(OpenFlags.ReadOnly);

    X509Certificate2Collection certColl =
        storeAddressBook.Certificates.Find(X509FindType.FindBySubjectName, recipientName, false);
    storeAddressBook.Close();

    if (certColl.Count != 0)
    {

        return certColl[0];
    }
    else
    {
        return null;
    }
}

私が見るように、Outlookの動作は異なります。レシピエントの公開証明書がローカルのマシン証明書マネージャーに存在しない場合でも。組織の中央サーバーまたは広告サーバー(私はそれについてはよくわかりません)から公開証明書を取得し、暗号化されたメールを送信することができます。

4

1 に答える 1

5
// Where ##### is the name of your AD server
DirectoryEntry de = new DirectoryEntry("LDAP://#####");
DirectorySearcher dsearch = new DirectorySearcher(de);

//Search how you want.  Google "LDAP Filter" for more.
dsearch.Filter = "(cn=#####)"; 
SearchResultCollection rc = dsearch.FindAll();
X509Certificate stt = new X509Certificate();

foreach (SearchResult r in rc)
{
    if (r.Properties.Contains("userCertificate"))
    {
        // This is hard coded to the first element.
        // Some users may have multiples.  Use ADSI Edit to find out more.
        Byte[] b = (Byte[])r.Properties["userCertificate"][0];
        X509Certificate cert1 = new X509Certificate(b);
    }
}
于 2012-06-26T21:44:55.540 に答える