You are here

public static function EncryptionKeyType::generateKeyValue in Key 8

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/EncryptionKeyType.php, line 101

Class

EncryptionKeyType
Defines a generic key type for encryption.

Namespace

Drupal\key\Plugin\KeyType

Code

public static function generateKeyValue(array $configuration) {
  if (!empty($configuration['key_size'])) {
    $bytes = $configuration['key_size'] / 8;
  }
  else {

    // If no key size has been defined, use 32 bytes as the default.
    $bytes = 32;
  }
  $random_key = random_bytes($bytes);
  return $random_key;
}