PHP implementation of SHA,SSHA,MD5 encryption method in LDAP ____php

Source: Internet
Author: User
Tags ldap md5 encryption pack sha1

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.