lithium\storage\session\strategy\Encrypt::_hashSecret()

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 aes-256-cbc 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.

Parameters

  • string $key

    The possibly too weak key.

Returns

string

The hashed (raw) key.

Source

	protected function _hashSecret($key) {
		if (strlen($key) >= 32) {
			return $key;
		}
		return substr(hash('sha256', $key, true), 0, 32);
	}