/**
  * Generate a new keypair
  * 
  * @param int $type Key flags
  * @param &string $secret_key - Reference to optional variable to store secret key in
  * @return KeyPair
  * @throws CryptoException\InvalidKey
  */
 public static function generate($type = Key::CRYPTO_BOX, &$secret_key = null)
 {
     if (Key::doesNotHaveFlag($type, Key::ASYMMETRIC)) {
         throw new CryptoException\InvalidKey('An asymmetric key type must be passed to KeyPair::generate()');
     }
     if (Key::hasFlag($type, Key::ENCRYPTION)) {
         $key = EncryptionSecretKey::generate(Key::CRYPTO_BOX, $secret_key);
         $keypair = new EncryptionKeyPair(...$key);
         return $keypair;
     }
     throw new CryptoException\InvalidKey('Only encryption keys can be generated.');
 }