PHPMailer\PHPMailer
SMTP::hmac
Calculate an MD5 HMAC hash. Works like hash_hmac('md5', $data, $key) in case that function is not available.
Method of the class: SMTP{}
No Hooks.
Returns
String.
Usage
// protected - for code of main (parent) or child class $result = $this->hmac( $data, $key );
- $data(string) (required)
- The data to hash.
- $key(string) (required)
- The key to hash with.
SMTP::hmac() SMTP::hmac code WP 7.0
protected function hmac($data, $key)
{
if (function_exists('hash_hmac')) {
return hash_hmac('md5', $data, $key);
}
//The following borrowed from
//https://www.php.net/manual/en/function.mhash.php#27225
//RFC 2104 HMAC implementation for php.
//Creates an md5 HMAC.
//Eliminates the need to install mhash to compute a HMAC
//by Lance Rushing
$bytelen = 64; //byte length for md5
if (strlen($key) > $bytelen) {
$key = pack('H*', md5($key));
}
$key = str_pad($key, $bytelen, chr(0x00));
$ipad = str_pad('', $bytelen, chr(0x36));
$opad = str_pad('', $bytelen, chr(0x5c));
$k_ipad = $key ^ $ipad;
$k_opad = $key ^ $opad;
return md5($k_opad . pack('H*', md5($k_ipad . $data)));
}