Ldap的md5加密

1、ldap的md5加密不仅仅是md5加密。

比如“123456”,通过ldap的md5加密是 “4QrcOUm6Wau+VuBX8g+IPg==” .

原来ldap的md5加密是先经过md5加密,再进行了base64的编码处理。整个过程通过c#解释,就是如下代码啦

 1  public static string LdapMD5AES(string clearPwd)
 2         {
 3            string md5Pwd = string.Empty;
 4            byte[] result = Encoding.Default.GetBytes(clearPwd);
 5            MD5 md5 = new MD5CryptoServiceProvider();
 6            byte[] output = md5.ComputeHash(result);
 7 
 8            return Convert.ToBase64String(output);
 9  
10         }


这是我写一个方法,把clear密码进行md5加密。过程很简单吧。

2、在ldap的每个entry的attributes里,可以存多个值得。如图:

 

其实,每个attributes的值是可以存储为一个数组的。所以在c#的存储过程中,你存入一个数组值就可以了。

存数据: 

request.Attributes.Add(new DirectoryAttribute("userPassword", new string[]{ user.Password,user.MD5Password}));


取值:

1  private T GetAttribute<T>(SearchResultEntry entry, string name) where T : class
2         {
3             if (entry.Attributes.Contains(name))
4             {
5                 return (T)(entry.Attributes[name].GetValues(typeof(T))[0]);
6             }
7 
8             return null;
9         }

在上面有个这句代码里 (entry.Attributes[name].GetValues(typeof(T))[0]); 索引值0即为默认取该attributes值对应value数组的第一个。如果读第二个值,你知道该怎么做的。呵呵。

 

posted @ 2014-04-02 14:45  rachelanlan  阅读(1036)  评论(0编辑  收藏  举报