phpseclib API Documentation
Class

Crypt_Hash

class Crypt_Hash

Pure-PHP implementations of keyed-hash message authentication codes (HMACs) and various cryptographic hashing functions.

Properties

int $hashParam Hash Parameter
int $b Byte-length of compression blocks / key (Internal HMAC)
int $l Byte-length of hash output (Internal HMAC)
string $hash Hash Algorithm
string $key Key
string $opad Outer XOR (Internal HMAC)
string $ipad Inner XOR (Internal HMAC)

Methods

Crypt_Hash Crypt_Hash(string $hash = 'sha1')

Default Constructor.

setKey(string $key = false)

Sets the key for HMACs

string getHash()

Gets the hash function.

setHash(string $hash)

Sets the hash function.

string hash(string $text)

Compute the HMAC.

int getLength()

Returns the hash length (in bytes)

_md5(string $m)

Wrapper for MD5

_sha1(string $m)

Wrapper for SHA1

_md2(string $m)

Pure-PHP implementation of MD2

_sha256(string $m)

Pure-PHP implementation of SHA256

_sha512(string $m)

Pure-PHP implementation of SHA384 and SHA512

int _rightRotate(int $int, int $amt)

Right Rotate

int _rightShift(int $int, int $amt)

Right Shift

int _not(int $int)

Not

int _add()

Add

string _string_shift(string $string, int $index = 1)

String Shift

Details

at line 154
public Crypt_Hash Crypt_Hash(string $hash = 'sha1')

Default Constructor.

Parameters

string $hash

Return Value

Crypt_Hash

at line 180
public setKey(string $key = false)

Sets the key for HMACs

Keys can be of any length.

Parameters

string $key

at line 193
public string getHash()

Gets the hash function.

As set by the constructor or by the setHash() method.

Return Value

string

at line 204
public setHash(string $hash)

Sets the hash function.

Parameters

string $hash

at line 312
public string hash(string $text)

Compute the HMAC.

Parameters

string $text

Return Value

string

at line 361
public int getLength()

Returns the hash length (in bytes)

Return Value

int

at line 372
public _md5(string $m)

Wrapper for MD5

Parameters

string $m

at line 383
public _sha1(string $m)

Wrapper for SHA1

Parameters

string $m

at line 396
public _md2(string $m)

Pure-PHP implementation of MD2

See {@link http://tools.ietf.org/html/rfc1319 RFC1319}.

Parameters

string $m

at line 472
public _sha256(string $m)

Pure-PHP implementation of SHA256

See {@link http://en.wikipedia.org/wiki/SHAhashfunctions#SHA-256.28aSHA-2variant.29pseudocode SHA-256 (a SHA-2 variant) pseudocode - Wikipedia}.

Parameters

string $m

at line 579
public _sha512(string $m)

Pure-PHP implementation of SHA384 and SHA512

Parameters

string $m

at line 765
public int _rightRotate(int $int, int $amt)

Right Rotate

Parameters

int $int
int $amt

Return Value

int

See also

self::_sha256()

at line 781
public int _rightShift(int $int, int $amt)

Right Shift

Parameters

int $int
int $amt

Return Value

int

See also

self::_sha256()

at line 795
public int _not(int $int)

Not

Parameters

int $int

Return Value

int

See also

self::_sha256()

at line 811
public int _add()

Add

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. MathBigInteger() could be used but this should be faster.

Return Value

int

See also

self::_sha256()

at line 837
public string _string_shift(string $string, int $index = 1)

String Shift

Inspired by array_shift

Parameters

string $string
int $index

Return Value

string