Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions | Data Fields | Static Protected Member Functions | Static Protected Attributes
Zend_Crypt_Hmac Class Reference
Inheritance diagram for Zend_Crypt_Hmac:
Zend_Crypt

Static Public Member Functions

static compute ($key, $hash, $data, $output=self::STRING)
 
- Static Public Member Functions inherited from Zend_Crypt
static hash ($algorithm, $data, $binaryOutput=false)
 

Data Fields

const STRING = 'string'
 
const BINARY = 'binary'
 
- Data Fields inherited from Zend_Crypt
const TYPE_OPENSSL = 'openssl'
 
const TYPE_HASH = 'hash'
 
const TYPE_MHASH = 'mhash'
 

Static Protected Member Functions

static _setHashAlgorithm ($hash)
 
static _hash ($data, $output=self::STRING, $internal=false)
 
static _getMhashDefinition ($hashAlgorithm)
 
- Static Protected Member Functions inherited from Zend_Crypt
static _detectHashSupport ($algorithm)
 
static _digestHash ($algorithm, $data, $binaryOutput)
 
static _digestMhash ($algorithm, $data, $binaryOutput)
 
static _digestOpenssl ($algorithm, $data, $binaryOutput)
 

Static Protected Attributes

static $_key = null
 
static $_packFormat = null
 
static $_hashAlgorithm = 'md5'
 
static $_supportedMhashAlgorithms
 
- Static Protected Attributes inherited from Zend_Crypt
static $_type = null
 
static $_supportedAlgosOpenssl
 
static $_supportedAlgosMhash
 

Detailed Description

Definition at line 39 of file Hmac.php.

Member Function Documentation

◆ _getMhashDefinition()

static _getMhashDefinition (   $hashAlgorithm)
staticprotected

Since MHASH accepts an integer constant representing the hash algorithm we need to make a small detour to get the correct integer matching our algorithm's name.

Parameters
string$hashAlgorithm
Returns
integer

Definition at line 173 of file Hmac.php.

174  {
175  for ($i = 0; $i <= mhash_count(); $i++)
176  {
177  $types[mhash_get_hash_name($i)] = $i;
178  }
179  return $types[strtoupper($hashAlgorithm)];
180  }
$i
Definition: gallery.phtml:31

◆ _hash()

static _hash (   $data,
  $output = self::STRING,
  $internal = false 
)
staticprotected

Perform HMAC and return the keyed data

Parameters
string$data
string$output
bool$internalOption to not use hash() functions for testing
Returns
string

Definition at line 147 of file Hmac.php.

148  {
149  if (function_exists('hash_hmac')) {
150  if ($output == self::BINARY) {
151  return hash_hmac(self::$_hashAlgorithm, $data, self::$_key, true);
152  }
153  return hash_hmac(self::$_hashAlgorithm, $data, self::$_key);
154  }
155 
156  if (function_exists('mhash')) {
157  if ($output == self::BINARY) {
158  return mhash(self::_getMhashDefinition(self::$_hashAlgorithm), $data, self::$_key);
159  }
160  $bin = mhash(self::_getMhashDefinition(self::$_hashAlgorithm), $data, self::$_key);
161  return bin2hex($bin);
162  }
163  }

◆ _setHashAlgorithm()

static _setHashAlgorithm (   $hash)
staticprotected

Setter for the hash method.

Parameters
string$hash
Exceptions
Zend_Crypt_Hmac_Exception
Returns
Zend_Crypt_Hmac

Definition at line 114 of file Hmac.php.

115  {
116  if (!isset($hash) || empty($hash)) {
117  #require_once 'Zend/Crypt/Hmac/Exception.php';
118  throw new Zend_Crypt_Hmac_Exception('provided hash string is null or empty');
119  }
120 
121  $hash = strtolower($hash);
122  $hashSupported = false;
123 
124  if (function_exists('hash_algos') && in_array($hash, hash_algos())) {
125  $hashSupported = true;
126  }
127 
128  if ($hashSupported === false && function_exists('mhash') && in_array($hash, self::$_supportedAlgosMhash)) {
129  $hashSupported = true;
130  }
131 
132  if ($hashSupported === false) {
133  #require_once 'Zend/Crypt/Hmac/Exception.php';
134  throw new Zend_Crypt_Hmac_Exception('hash algorithm provided is not supported on this PHP installation; please enable the hash or mhash extensions');
135  }
136  self::$_hashAlgorithm = $hash;
137  }

◆ compute()

static compute (   $key,
  $hash,
  $data,
  $output = self::STRING 
)
static

Performs a HMAC computation given relevant details such as Key, Hashing algorithm, the data to compute MAC of, and an output format of String, Binary notation or BTWOC.

Parameters
string$key
string$hash
string$data
string$output
Exceptions
Zend_Crypt_Hmac_Exception
Returns
string

Definition at line 91 of file Hmac.php.

92  {
93  // set the key
94  if (!isset($key) || empty($key)) {
95  #require_once 'Zend/Crypt/Hmac/Exception.php';
96  throw new Zend_Crypt_Hmac_Exception('provided key is null or empty');
97  }
98  self::$_key = $key;
99 
100  // set the hash
102 
103  // perform hashing and return
104  return self::_hash($data, $output);
105  }
static _hash($data, $output=self::STRING, $internal=false)
Definition: Hmac.php:147
static _setHashAlgorithm($hash)
Definition: Hmac.php:114

Field Documentation

◆ $_hashAlgorithm

$_hashAlgorithm = 'md5'
staticprotected

Definition at line 62 of file Hmac.php.

◆ $_key

$_key = null
staticprotected

Definition at line 47 of file Hmac.php.

◆ $_packFormat

$_packFormat = null
staticprotected

Definition at line 54 of file Hmac.php.

◆ $_supportedMhashAlgorithms

$_supportedMhashAlgorithms
staticprotected
Initial value:
= array('adler32',' crc32', 'crc32b', 'gost',
'haval128', 'haval160', 'haval192', 'haval256', 'md4', 'md5', 'ripemd160',
'sha1', 'sha256', 'tiger', 'tiger128', 'tiger160')

Definition at line 69 of file Hmac.php.

◆ BINARY

const BINARY = 'binary'

Definition at line 77 of file Hmac.php.

◆ STRING

const STRING = 'string'

Constants representing the output mode of the hash algorithm

Definition at line 76 of file Hmac.php.


The documentation for this class was generated from the following file: