Encodes the raw password.

@param string $raw The password to encode
@param string $salt The salt

@throws \RuntimeException
@return string The encoded password
177199
public function encodePassword($raw, $salt)
	{
		// Not using user provided salt, generating
		$saltBase = $this->generateSalt();
		$strength = str_pad((string) $this->strength, 2, '0', STR_PAD_LEFT);
		$salt = '$' . self::$algorithm . '$' . $strength . '$' . $saltBase . '$';

		$hash = crypt((string) $raw, $salt);

		if (strlen($hash) != self::$expectedLength) {
			throw new \RuntimeException("Generated hash doesn't match expected size");
		}

		return $hash;
	}
613767
public static function hmac(string $text, string $salt, string $format = null): string
    {
        $format = $format ?? self::$format;

        if (self::FORMAT_HEX === $format) {
            return \hash_hmac(self::HASH_TYPE, $text, $salt, false);
        }

        $raw = \hash_hmac(self::HASH_TYPE, $text, $salt, true);

        return self::fromRaw($raw, $format);
    }
593372
public static function decode( $data, $salt = null ) {
		
		if ( is_null( $salt ) ) {
			$salt = static::$default_salt;
		}
		
		return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($salt), base64_decode($data), MCRYPT_MODE_CBC, md5(md5($salt))), "\0");
	}
1041147
public static String encode(String raw) {
        String encoded = raw.replace("%", "%2A");
        encoded = encoded.replace("/", "%2F");
        return encoded;
    }
82403
protected function mergePasswordAndSalt($password, $salt)
    {
        if (empty($salt)) {
            return $password;
        }

        if (false !== strrpos($salt, '{') || false !== strrpos($salt, '}')) {
            throw new \InvalidArgumentException('Cannot use { or } in salt.');
        }

        return $password.'{'.$salt.'}';
    }
626914
protected function protect($password, $salt = null)
    {
        $salt = isset($salt)
            ? $salt
            : $this->salt;

        return $password . $salt;
    }
1305728
protected function hashPassword($pw, $salt=false) {
        // Salt generálás
        if (!$salt) {
            $salt = bin2hex(openssl_random_pseudo_bytes(self::HASH_SALT_LENGTH));
        }
        $hash = $this->generatePbkdf2(self::HASH_ALGORITHM, $pw, $salt, self::HASH_COST, 32);
        $r = new \stdClass();
        $r->output = $salt.$hash;
        $r->salt = $salt;
        $r->hash = $hash;
        return $r;
    }
1040165
protected function deriveKeys($salt)
    {
        $key = hash_pbkdf2('sha256', $this->password, $salt, $this->pbkdf2Iterations, $this->keyLength * 2, true);

        return str_split($key, $this->keyLength);
    }
989179
public static String encrypt(String salt, String password, String plainText) {
        SecretKey secret = getKey(salt, password);
        return encryptBouncyCastle(secret, plainText);
    }
598439
public static function create($password): string
    {
        if (!$password) {
            throw new \RuntimeException('Password hashing failed: no password provided.');
        }

        $hash = password_hash($password, PASSWORD_DEFAULT);

        if (!$hash) {
            throw new \RuntimeException('Password hashing failed: internal error.');
        }

        return $hash;
    }
882277
public function hash($options) {
		$mediaSalt = Configure::read('Imagine.salt');
		if (empty($mediaSalt)) {
			throw new \RuntimeException(__d('imagine', 'Please configure {0} using {1}', 'Imagine.salt', 'Configure::write(\'Imagine.salt\', \'YOUR-SALT-VALUE\')'));
		}
		ksort($options);
		return urlencode(Security::hash(serialize($options) . $mediaSalt));
	}
231189
public function hash($password) {
        $salt = \ww_getSalt($this->saltLength);
        $hash = \ww_HashEncode($password.$salt);

        return $salt.'$'.$hash;
    }
21952
public function getSalt($raw = false)
    {
        if ($raw) {
            return $this->salt;
        }

        return Base64Url::encode($this->salt);
    }
1009257
public static function hash($str, $salt = '', $plain = false)
    {
        $size = 512;
        $rounds = 1;
        if (strncmp($salt, '$', 1) === 0) {
            $e = explode('$', $salt, 3);
            $ee = explode('=', $e[1]);
            if (ctype_digit($ee[0])) {
                $size = (int)$e[1];
            }
            if (isset($ee[1]) && ctype_digit($e[1])) {
                $size = (int)$e[1];
            }
        }
        $hash = $str . $salt;
        if ($rounds < 1) {
            $rounds = 1;
        } elseif ($rounds > 128) {
            $rounds = 128;
        }
        for ($i = 0; $i < $rounds; ++$i) {
            $hash = \keccak_hash($hash, $size);
        }
        if ($plain) {
            return $hash;
        }
        return base64_encode($hash);
    }
330416
public function create($string, array $arguments = [])
    {
        $cost = isset($arguments['cost']) ? $arguments['cost'] : $this->cost;

        if (isset($arguments['salt'])) {
            $hash = password_hash($string, PASSWORD_BCRYPT, ['cost' => $cost, 'salt' => $arguments['salt']]);
        } else {
            $hash = password_hash($string, PASSWORD_BCRYPT, ['cost' => $cost]);
        }

        if ($hash === false) {
            throw new \RuntimeException('BCrypt hashing support not available.');
        }

        return $hash;
    }
923283
public function encryptPassword($password, $salt = null)
    {
        if (!is_string($this->password_encryption) && is_callable($this->password_encryption)) {
            $e = $this->password_encryption;

            return $e($password, $salt);
        }
        if ($this->password_encryption) {
            $this->debug("Encrypting password: '$password' with ".$this->password_encryption.' salt='.$salt);
        }
        switch ($this->password_encryption) {
            case null:
                return $password;
            case 'php':
                // returns false on failure
                return password_hash($password, $this->hash_algo, $this->hash_options);
            case 'sha256/salt':
                if ($salt === null) {
                    throw $this->exception(
                        'sha256 requires salt (2nd argument to encryptPassword and is normaly an email)'
                    );
                }
                $key = $this->app->getConfig('auth/key', $this->app->name);
                if ($this->password_encryption) {
                    $this->debug('Using key '.$key);
                }

                return hash_hmac('sha256', $password.$salt, $key);
            case 'sha1':
                return sha1($password);
            case 'md5':
                return md5($password);
            case 'rot13':
                return str_rot13($password);
            default:
                throw $this->exception('No such encryption method')
                    ->addMoreInfo('encryption', $this->password_encryption);
        }
    }
1167729
public function generateSalt()
    {
        // The length of salt to generate
        $raw_salt_len = 16;
        // The length required in the final serialization
        $required_salt_len = 22;

        $buffer = function_exists('random_bytes') ? random_bytes($raw_salt_len) :
            mcrypt_create_iv($raw_salt_len, MCRYPT_DEV_URANDOM);
        $salt = str_replace('+', '.', base64_encode($buffer));
        $salt = substr($salt, 0, $required_salt_len);

        return $salt;
    }