Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to add a certificate to LDAP server created?

I created a LDAP Server with name NESTIT-283. But with it I am able to fetch the objectclass,adspath,domain component alone.
My code is as below:
C#
DirectoryEntry de = new DirectoryEntry("LDAP://NESTIT-283/dc=maxcrc,dc=com");//Where ##### is the name of your AD server
                  de.AuthenticationType = AuthenticationTypes.None;
                  DirectorySearcher dsearch = new DirectorySearcher(de);
                  //dsearch.Filter = "(cn=Alexander.junior)"; //Search how you want.  Google "LDAP Filter" for more.
                  SearchResultCollection rc = dsearch.FindAll();
                  int cnt = rc.Count;
                  X509Certificate stt = new X509Certificate();

                  foreach (SearchResult r in rc)
                  {
                      string s = r.Properties["objectClass"][0].ToString();
                      string s1 = r.Properties["adspath"][0].ToString();
                      string s2 = r.Properties["dc"][0].ToString();

                      if (r.Properties.Contains("userCertificate"))
                      {
                          
                          Byte[] b = (Byte[])r.Properties["userCertificate"][0];  //This is hard coded to the first element.  Some users may have multiples.  Use ADSI Edit to find out more.
                          X509Certificate cert1 = new X509Certificate(b);
                      }
                  }
Posted
Updated 27-Oct-15 11:56am
v2

1 solution

hello

to store certificate it could be done as follow

C#
byte[] certData = (byte[]) r.Properties["userCertificate"][0];
X509Certificate cert = new X509Certificate(certData);
r.Properties["userCertificate"].Clear();
r.CommitChanges();
r.Properties["userCertificate"].Add(cert.GetRawCertData());
r.CommitChanges();



I hope that it would help and that was what you were looking for
 
Share this answer
 
v2
Comments
Korathu123 28-Oct-15 0:49am    
Actually Certificate Addition to the LDAP Server will be done by the Client in real time case.What But to test locally I want to store a certificate manually or code wise to the LDAP Server. Then I need to fetch the certificate Name from the LDAP Server.
Korathu123 28-Oct-15 0:55am    
Tried Above Code to add certificate to the LDAP Server.
Here in the above code the method Add and Commmit Changes aren't there for the object of Searchresultcollection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900