Click here to Skip to main content
15,902,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert the byte array fetched from LDAP Server to certificate file in c#?

I am fetching the certificate from LDAP Server. I am getting the same as a binary file. Want to fetch the corresponding certificate for the same and add to the store.
My code is a below:
string test = "LDAP://" + ldapserver + "/" + ldapbasedn;
using (DirectoryEntry entry = new DirectoryEntry("LDAP://" + ldapserver + "/" + ldapbasedn, ldapuser, ldappassword, AuthenticationTypes.None))
{
DirectorySearcher ds = new DirectorySearcher(entry);
ds.SearchScope = SearchScope.Subtree;
//ds.Filter = string.Format(ldapfilter, user);
SearchResultCollection result = ds.FindAll();
int i = 0;
foreach (SearchResult r in result)
{
//string s = r.Properties["objectClass"][i].ToString();
//string s1 = r.Properties["adspath"][i].ToString();
//string s2 = r.Properties["dc"][i].ToString();
if (r.Properties.Contains("usercertificate;binary"))
{


Byte[] b = (Byte[])r.Properties["usercertificate;binary"][i];
}
}
Posted

1 solution

I don't know that exactly LDAP server sends in that byte array but if there is a true certificate then You could just write it as a file and C# certificate class allows You to load it from file.
Otherwise if there is a serialized C# class certificate in that array You can use marshaling or just deserializing.
To serialize/deserialize You need ISerializable interface.

I don't know if this answers You question but at least I tried :)
 
Share this answer
 

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