You are here

KeyGenerator.php in Simple OAuth (OAuth2) & OpenID Connect 8.4

Same filename and directory in other branches
  1. 8.3 src/Service/KeyGenerator.php
  2. 5.x src/Service/KeyGenerator.php

File

src/Service/KeyGenerator.php
View source
<?php

namespace Drupal\simple_oauth\Service;


/**
 * @internal
 */
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'],
    ];
  }

}

Classes

Namesort descending Description
KeyGenerator @internal