Back to CryptoCipher class

Method generateKey

public \Joomla\Crypt\Key
generateKey
(array $options = array())
Method to generate a new encryption key object.
Parameters
  • array $options Key generation options.
Returns
  • \Joomla\Crypt\Key
Since
  • 3.5
-
  • \RuntimeException
Class: CryptoCipher
Project: Joomla

Method generateKey - Source code

/**
 * Method to generate a new encryption key object.
 *
 * @param   array  $options  Key generation options.
 *
 * @return  Key
 *
 * @since   3.5
 * @throws  \RuntimeException
 */
public function generateKey(array $options = array())
{
    // Generate the encryption key.
    try {
        $public = \Crypto::CreateNewRandomKey();
    } catch (\CryptoTestFailedException $ex) {
        throw new \RuntimeException('Cannot safely create a key', $ex->getCode(), $ex);
    } catch (\CannotPerformOperationException $ex) {
        throw new \RuntimeException('Cannot safely create a key', $ex->getCode(), $ex);
    }
    // Explicitly flag the private as unused in this cipher.
    $private = 'unused';
    return new Key('crypto', $private, $public);
}