Hash
in package
Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.
Tags
Table of Contents
- MODE_HASH = 3
- Toggles the hash() implementation, which works on PHP 5.1.2+.
- MODE_INTERNAL = 1
- Toggles the internal implementation
- MODE_MHASH = 2
- Toggles the mhash() implementation, which has been deprecated on PHP 5.3.0+.
- $b : int
- Byte-length of compression blocks / key (Internal HMAC)
- $computedKey : string
- Computed Key
- $engine : string
- Engine
- $hash : string
- Hash Algorithm
- $hashParam : int
- Hash Parameter
- $ipad : string
- Inner XOR (Internal HMAC)
- $key : string
- Key
- $l : int
- Byte-length of hash output (Internal HMAC)
- $opad : string
- Outer XOR (Internal HMAC)
- __construct() : Hash
- Default Constructor.
- _add() : int
- Add
- _computeKey() : mixed
- Pre-compute the key used by the HMAC
- _md2() : mixed
- Pure-PHP implementation of MD2
- _md5() : mixed
- Wrapper for MD5
- _not() : int
- Not
- _rightRotate() : int
- Right Rotate
- _rightShift() : int
- Right Shift
- _sha1() : mixed
- Wrapper for SHA1
- _sha256() : mixed
- Pure-PHP implementation of SHA256
- _sha512() : mixed
- Pure-PHP implementation of SHA384 and SHA512
- _string_shift() : string
- String Shift
- getHash() : string
- Gets the hash function.
- getLength() : int
- Returns the hash length (in bytes)
- hash() : string
- Compute the HMAC.
- setHash() : mixed
- Sets the hash function.
- setKey() : mixed
- Sets the key for HMACs
Constants
MODE_HASH
Toggles the hash() implementation, which works on PHP 5.1.2+.
public
mixed
MODE_HASH
= 3
MODE_INTERNAL
Toggles the internal implementation
public
mixed
MODE_INTERNAL
= 1
MODE_MHASH
Toggles the mhash() implementation, which has been deprecated on PHP 5.3.0+.
public
mixed
MODE_MHASH
= 2
Properties
$b
Byte-length of compression blocks / key (Internal HMAC)
public
int
$b
Tags
$computedKey
Computed Key
public
string
$computedKey
= false
Tags
$engine
Engine
public
string
$engine
Tags
$hash
Hash Algorithm
public
string
$hash
Tags
$hashParam
Hash Parameter
public
int
$hashParam
Tags
$ipad
Inner XOR (Internal HMAC)
public
string
$ipad
Tags
$key
Key
public
string
$key
= false
Tags
$l
Byte-length of hash output (Internal HMAC)
public
int
$l
= false
Tags
$opad
Outer XOR (Internal HMAC)
public
string
$opad
Tags
Methods
__construct()
Default Constructor.
public
__construct([string $hash = 'sha1' ]) : Hash
Parameters
- $hash : string = 'sha1'
Tags
Return values
Hash —_add()
Add
public
_add() : int
_sha256() adds multiple unsigned 32-bit integers. Since PHP doesn't support unsigned integers and since the possibility of overflow exists, care has to be taken. BigInteger could be used but this should be faster.
Tags
Return values
int —_computeKey()
Pre-compute the key used by the HMAC
public
_computeKey() : mixed
Quoting http://tools.ietf.org/html/rfc2104#section-2, "Applications that use keys longer than B bytes will first hash the key using H and then use the resultant L byte string as the actual key to HMAC."
As documented in https://www.reddit.com/r/PHP/comments/9nct2l/symfonypolyfill_hash_pbkdf2_correct_fix_for/ when doing an HMAC multiple times it's faster to compute the hash once instead of computing it during every call
Tags
Return values
mixed —_md2()
Pure-PHP implementation of MD2
public
_md2(string $m) : mixed
See RFC1319.
Parameters
- $m : string
Tags
Return values
mixed —_md5()
Wrapper for MD5
public
_md5(string $m) : mixed
Parameters
- $m : string
Tags
Return values
mixed —_not()
Not
public
_not(int $int) : int
Parameters
- $int : int
Tags
Return values
int —_rightRotate()
Right Rotate
public
_rightRotate(int $int, int $amt) : int
Parameters
- $int : int
- $amt : int
Tags
Return values
int —_rightShift()
Right Shift
public
_rightShift(int $int, int $amt) : int
Parameters
- $int : int
- $amt : int
Tags
Return values
int —_sha1()
Wrapper for SHA1
public
_sha1(string $m) : mixed
Parameters
- $m : string
Tags
Return values
mixed —_sha256()
Pure-PHP implementation of SHA256
public
_sha256(string $m) : mixed
Parameters
- $m : string
Tags
Return values
mixed —_sha512()
Pure-PHP implementation of SHA384 and SHA512
public
_sha512(string $m) : mixed
Parameters
- $m : string
Tags
Return values
mixed —_string_shift()
String Shift
public
_string_shift(string &$string[, int $index = 1 ]) : string
Inspired by array_shift
Parameters
- $string : string
- $index : int = 1
Tags
Return values
string —getHash()
Gets the hash function.
public
getHash() : string
As set by the constructor or by the setHash() method.
Tags
Return values
string —getLength()
Returns the hash length (in bytes)
public
getLength() : int
Tags
Return values
int —hash()
Compute the HMAC.
public
hash(string $text) : string
Parameters
- $text : string
Tags
Return values
string —setHash()
Sets the hash function.
public
setHash(string $hash) : mixed
Parameters
- $hash : string
Tags
Return values
mixed —setKey()
Sets the key for HMACs
public
setKey([string $key = false ]) : mixed
Keys can be of any length.
Parameters
- $key : string = false