A few days ago because of the work of the relationship between the need to use PHP simulation LDAP sha,ssha,md5 encryption method, originally thought that the use of SH1 (), MD5 () such a method can be achieved, but this finished after the discovery of the generated encrypted string, in the LDAP decryption is wrong, Later checked the data to find that the LDAP Sha,ssha,md5 encryption method is a special treatment, specifically as follows:
sha Encryption Method :
/**
* SHA Encryption
* @param $password strings that need to be encrypted
* @return A string that returns an encryption number
* */
Public Function Ldap_sha ($password)
{
$ldap _passwd = "{SHA}". Base64_encode (Pack ("h*", SHA1 ($password)));
return $LDAP _passwd;
}
Ssha Encryption Method:
/**
* Ssha Encryption algorithm
* @param $password strings that need to be encrypted
* @return A string that returns an encryption number
* */
Public Function Ldap_ssha ($password)
{
$salt = "";
For ($i =1 $i <=10; $i + +)
{
$salt. = substr (' 0123456789abcdef ', rand (0,15), 1);
}
$hash = "{Ssha}". Base64_encode (Pack ("h*", SHA1 ($password. $salt)). $salt);
return $hash;
}
MD5 Encryption Method:
/**
* MD5 Encryption
* @param $password strings that need to be encrypted
* @return A string that returns an encryption number
* */
Public Function ldap_md5 ($password)
{
$MD 5 = "{MD5}". Base64_encode (Pack (' h* ', MD5 ($password)));
return $MD 5;
}
Reference: HTTP://WWW.XIAOLANGSPACE.COM/ARCHIVES/22