You are here

class KeyGenerator in Simple OAuth (OAuth2) & OpenID Connect 8.4

Same name and namespace in other branches
  1. 8.3 src/Service/KeyGenerator.php \Drupal\simple_oauth\Service\KeyGenerator
  2. 5.x src/Service/KeyGenerator.php \Drupal\simple_oauth\Service\KeyGenerator

@internal

Hierarchy

Expanded class hierarchy of KeyGenerator

File

src/Service/KeyGenerator.php, line 8

Namespace

Drupal\simple_oauth\Service
View source
class KeyGenerator {
  const CERT_CONFIG = [
    "digest_alg" => "sha512",
    "private_key_bits" => 4096,
    "private_key_type" => OPENSSL_KEYTYPE_RSA,
  ];

  /**
   * Generate a private and public key.
   *
   * @return array with the generated public and private key
   */
  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'],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
KeyGenerator::CERT_CONFIG constant
KeyGenerator::generateKeys public static function Generate a private and public key.