Jose\Factory\JWKFactory::createKey PHP Method

createKey() public static method

public static createKey ( array $config )
$config array
    public static function createKey(array $config)
    {
        Assertion::keyExists($config, 'kty', 'The key "kty" must be set');
        $supported_types = ['RSA' => 'RSA', 'OKP' => 'OKP', 'EC' => 'EC', 'oct' => 'Oct', 'none' => 'None'];
        $kty = $config['kty'];
        Assertion::keyExists($supported_types, $kty, sprintf('The key type "%s" is not supported. Please use one of %s', $kty, json_encode(array_keys($supported_types))));
        $method = sprintf('create%sKey', $supported_types[$kty]);
        return self::$method($config);
    }

Usage Example

Beispiel #1
0
 /**
  * @return \Jose\Object\JWKInterface
  */
 protected function createJWK()
 {
     $data = JWKFactory::createKey($this->parameters)->getAll();
     $data['kid'] = Base64Url::encode(random_bytes(64));
     return JWKFactory::createFromValues($data);
 }