Jose\Algorithm\KeyEncryption\PBES2AESKW::wrapKey PHP Method

wrapKey() public method

public wrapKey ( Jose\Object\JWKInterface $key, $cek, array $complete_headers, array &$additional_headers )
$key Jose\Object\JWKInterface
$complete_headers array
$additional_headers array
    public function wrapKey(JWKInterface $key, $cek, array $complete_headers, array &$additional_headers)
    {
        $this->checkKey($key);
        $this->checkHeaderAlgorithm($complete_headers);
        $wrapper = $this->getWrapper();
        $hash_algorithm = $this->getHashAlgorithm();
        $key_size = $this->getKeySize();
        $salt = random_bytes($this->salt_size);
        $password = Base64Url::decode($key->get('k'));
        // We set headers parameters
        $additional_headers['p2s'] = Base64Url::encode($salt);
        $additional_headers['p2c'] = $this->nb_count;
        $derived_key = hash_pbkdf2($hash_algorithm, $password, $complete_headers['alg'] . "" . $salt, $this->nb_count, $key_size, true);
        return $wrapper->wrap($derived_key, $cek);
    }