You are here

public static function KeyGenerator::generateKeys in Simple OAuth (OAuth2) & OpenID Connect 5.x

Same name and namespace in other branches
  1. 8.4 src/Service/KeyGenerator.php \Drupal\simple_oauth\Service\KeyGenerator::generateKeys()
  2. 8.3 src/Service/KeyGenerator.php \Drupal\simple_oauth\Service\KeyGenerator::generateKeys()

Generate a private and public key.

Return value

array with the generated public and private key

1 call to KeyGenerator::generateKeys()
KeyGeneratorService::generateKeys in src/Service/KeyGeneratorService.php
Generate both public key and private key on the given paths.

File

src/Service/KeyGenerator.php, line 21

Class

KeyGenerator
@internal

Namespace

Drupal\simple_oauth\Service

Code

public static function generateKeys() {

  // Generate Resource.
  $resource = openssl_pkey_new(KeyGenerator::CERT_CONFIG);

  // Get Private Key.
  openssl_pkey_export($resource, $pkey);

  // Get Public Key.
  $pubkey = openssl_pkey_get_details($resource);
  return [
    'private' => $pkey,
    'public' => $pubkey['key'],
  ];
}