You are here

public static function JwtRsKeyType::generateKeyValue in JSON Web Token Authentication (JWT) 8

Same name and namespace in other branches
  1. 8.0 src/Plugin/KeyType/JwtRsKeyType.php \Drupal\jwt\Plugin\KeyType\JwtRsKeyType::generateKeyValue()

Generate a key value of this type using the submitted configuration.

Parameters

array $configuration: The configuration for the key type plugin.

Return value

string The generated key value.

Overrides KeyTypeInterface::generateKeyValue

File

src/Plugin/KeyType/JwtRsKeyType.php, line 71

Class

JwtRsKeyType
Defines a key type for JWT RSA Signatures.

Namespace

Drupal\jwt\Plugin\KeyType

Code

public static function generateKeyValue(array $configuration) {
  $algorithm_keysize = self::getAlgorithmKeysize();
  $algorithm = $configuration['algorithm'];
  if (empty($algorithm) || !isset($algorithm_keysize[$algorithm])) {
    $algorithm = 'RS256';
  }
  $key_resource = openssl_pkey_new([
    'private_key_bits' => $algorithm_keysize[$algorithm],
    'private_key_type' => OPENSSL_KEYTYPE_RSA,
  ]);
  $key_string = '';
  openssl_pkey_export($key_resource, $key_string);
  openssl_pkey_free($key_resource);
  return $key_string;
}