\Gishiki\Security\HashingAlgorithm

This class is a collection of supported algorithms.

Note: This class uses OpenSSL for strong encryption

Summary

Methods
Properties
Constants
opensslHash()
opensslVerify()
rot13Hash()
rot13Verify()
bcryptHash()
bcryptVerify()
pbkdf2Hash()
pbkdf2Verify()
pbkdf2()
No public properties found
CRC32
MD4
MD5
SHA1
SHA256
SHA328
SHA512
ROT13
BCRYPT
PBKDF2
No protected methods found
No protected properties found
N/A
No private methods found
$pbkdf2Delimiter
N/A

Constants

CRC32

CRC32

MD4

MD4

MD5

MD5

SHA1

SHA1

SHA256

SHA256

SHA328

SHA328

SHA512

SHA512

ROT13

ROT13

BCRYPT

BCRYPT

PBKDF2

PBKDF2

Properties

$pbkdf2Delimiter

$pbkdf2Delimiter : 

Type

Methods

opensslHash()

opensslHash(string  $message, string  $algorithm) : string

Generate the message digest for the given message using the OpenSSL library

An example usage is:

$message = "this is the message to be hashed";

$test_gishiki_md5 = Algorithm::opensslHash($message, Algorithm::MD5);

echo "The hash of the message is: $test_gishiki_md5";

This function should be called from an Hasher object.

Parameters

string $message

the string to be hashed

string $algorithm

the name of the hashing algorithm

Throws

\InvalidArgumentException

the message is given as a non-string or an empty string

\Gishiki\Security\Hashing\HashingException

the error occurred while generating the hash for the given message

Returns

string —

the result of the hash algorithm

opensslVerify()

opensslVerify(string  $message, string  $digest,   $algorithm) : string

Check if the digest is the hash of the given message (using OpenSSL algorithms).

This function should be called from an Hasher object.

Parameters

string $message

the string to be checked against the message digest

string $digest

the message digest to be checked

$algorithm

Throws

\InvalidArgumentException

the message or the message digest is given as a non-string or an empty string

Returns

string —

the result of the hash algorithm

rot13Hash()

rot13Hash(string  $message) : string

Generate the rot13 for the given message.

An example usage is:

echo "You should watch Star Wars VII to find out that " . Algorithm::rot13Hash("Han Solo dies.", 'rot13');

This function should be called from an Hasher object.

Parameters

string $message

the string to be hashed

Throws

\InvalidArgumentException

the message is given as a non-string or an empty string

Returns

string —

the result of the hash algorithm

rot13Verify()

rot13Verify(string  $message, string  $digest) : string

Check if the digest is rot13 hash of the given message.

This function should be called from an Hasher object.

Parameters

string $message

the string to be checked against the message digest

string $digest

the message digest to be checked

Throws

\InvalidArgumentException

the message or the message digest is given as a non-string or an empty string

Returns

string —

the result of the hash algorithm

bcryptHash()

bcryptHash(string  $message) : string

Generate the message digest for the given message using the default PHP bcrypt implementation.

The BCrypt algorithm is thought to provide a secure way of storing passwords. This function should be NEVER called directly: use an instance of the Hasher class!

Parameters

string $message

the string to be hashed

Throws

\InvalidArgumentException

the message is given as a non-string or an empty string

\Gishiki\Security\Hashing\HashingException

the error occurred while generating the hash for the given message

Returns

string —

the result of the hash algorithm

bcryptVerify()

bcryptVerify(string  $message, string  $digest) : string

Check if the digest is bcrypt hash of the given message.

This function should be called from an Hasher object.

Parameters

string $message

the string to be checked against the message digest

string $digest

the message digest to be checked

Throws

\InvalidArgumentException

the message or the message digest is given as a non-string or an empty string

Returns

string —

the result of the hash algorithm

pbkdf2Hash()

pbkdf2Hash(string  $message) : string

Generate the message digest for the given message using the pbkdf2 algorithm.

The pbkdf2 algorithm is thought to be slow and produce an hash. This function should be NEVER called directly: use an instance of the Hasher class!

Parameters

string $message

the string to be hashed

Throws

\InvalidArgumentException

the message is given as a non-string or an empty string

\Gishiki\Security\Hashing\HashingException

the error occurred while generating the hash for the given message

Returns

string —

the result of the hash algorithm

pbkdf2Verify()

pbkdf2Verify(string  $message, string  $digest) : string

Check if the digest is the pbkdf2 hash of the given message.

This function should be called from an Hasher object.

Parameters

string $message

the string to be checked against the message digest

string $digest

the message digest to be checked

Throws

\InvalidArgumentException

the message or the message digest is given as a non-string or an empty string

Returns

string —

the result of the hash algorithm

pbkdf2()

pbkdf2(string  $password, string  $salt, string  $keyLength, string  $count, string  $algorithm = self::SHA256) : string

PBKDF2 key derivation function as defined by RSA's PKCS #5: https://www.ietf.org/rfc/rfc2898.txt.

Test vectors can be found here: https://www.ietf.org/rfc/rfc6070.txt

This implementation of PBKDF2 was originally created by https://defuse.ca With improvements by http://www.variations-of-shadow.com

Parameters

string $password

the password

string $salt

a salt that is unique to the password

string $keyLength

the length of the derived key in bytes

string $count

iteration count. Higher is better, but slower. Recommended: At least 1000

string $algorithm

the hash algorithm to use. Recommended: SHA256

Throws

\InvalidArgumentException

invalid arguments have been passed

\Gishiki\Security\Hashing\HashingException

the error occurred while generating the requested hashing algorithm

Returns

string —

the key derived from the password and salt