protected method

Hashes the given secret to make harder to detect.

This method figures out the appropriate key size for the chosen encryption algorithm and then hashes the given key accordingly. Note that if the key has already the needed length, it is considered to be hashed (secure) already and is therefore not hashed again. This lets you change the hashing method in your own code if you like.

The default MCRYPT_RIJNDAEL_128 key should be 32 byte long sha256 is used as the hashing algorithm. If the key size is shorter than the one generated by sha256, the first n bytes will be used.


  • string $key

    The possibly too weak key.



The hashed (raw) key.


	protected function _hashSecret($key) {
		$size = mcrypt_enc_get_key_size(static::$_resource);

		if (strlen($key) >= $size) {
			return $key;

		return substr(hash('sha256', $key, true), 0, $size);