Generate a secure key for use in cryptographic methods, optionally setting it in `app/config/config.php`.

eg: `gen aes set`
eg: `gen sha 32 set-lead`
eg: `gen sha 32 set-tail`

@param array $args The arguements.
340729
public function gen($args){

        if($args[0]=='aes'){
            $r = \Disco\manage\Manager::genAES256Key();
            if(isset($args[1]) && $args[1]=='set'){
                \Disco\manage\Manager::setAES256Key($r);
                echo '`AES_KEY256` now set to : ' . $r . PHP_EOL;
            }//if
            else {
                echo $r . PHP_EOL;
            }//el
        }//if
        else if($args[0]=='sha'){

            if(empty($args[1])){
                echo 'You must specify a length for the SHA512 salt' . PHP_EOL;
                exit;
            }//if

            $s = \Disco\manage\Manager::genSalt($args[1]);

            if(!empty($args[2]) && $args[2]=='set'){
                \Disco\manage\Manager::setSalt($s);
                echo '`SHA512_SALT` now set to : ' . $s . PHP_EOL;
            }//if
            else {
                echo $s . PHP_EOL;
            }//el

        } else {
            echo 'You must specify what to gen, either `aes` or `sha`' . PHP_EOL;
        }//el


    }
981470
public function prePersist(LifecycleEventArgs $args)
    {
        $entity = $args->getEntity();

        if ($this->checkEntityType($entity)) {
            $password = $entity->getPassword();

            if (!empty($password)) {
                $encodedPassword = $this->encryptPassword($password);
                $entity->setPassword($encodedPassword);
            }
        }
    }
1356077
public static function keyMatch3Func(...$args)
    {
        $name1 = $args[0];
        $name2 = $args[1];

        return self::keyMatch3($name1, $name2);
    }
539939
public function run(array $args)
    {
        print PHP_EOL;

        $command = 'help';

        //as in 'eve generate'
        if(isset($args[1])) {
            $command = $args[1];
        }

        $class = '\\Eve\\Framework\\Cli\\'.ucwords($command);

        if(!class_exists($class)) {
            self::error('No such command `'.$command.'` found.');
        }

        array_shift($args);
        $runner = new $class($this->cwd);

        $results = $runner->run($args);

        print PHP_EOL;

        return $results;
    }
1263715
public function qrPay(array $args = array()) {
        $url = $this->getPayQr()->parameters($this->merge($args))->getUrl();
        return (new QrCode())->create((string)$url);
    }
58549
public function generateKey(array $options = [])
	{
		// Generate the encryption key.
		$pair = Compat::crypto_box_keypair();

		return new Key('sodium', Compat::crypto_box_secretkey($pair), Compat::crypto_box_publickey($pair));
	}
1199219
public static function prepareCommand(array $args)
    {
        $return = '*' . \count($args) . "\r\n";
        foreach ($args as $arg) {
            $return .= '$' . \strlen($arg) . "\r\n" . $arg . "\r\n";
        }

        return $return;
    }
1167537
public static function keyMatch2Func(...$args)
    {
        $name1 = $args[0];
        $name2 = $args[1];

        return self::keyMatch2($name1, $name2);
    }
1254847
protected function getFromMethod($args)
    {
        if (!$method = $this->getKeyMethod($args)) {
            return '';
        }

        array_shift($args);

        return call_user_func([$this, $method], ...$args);
    }
758013
public function generateKeys($objectIds, $args) {
        $arguments = func_get_args();
        $objectIds = array_shift($arguments);
        if (!is_array($objectIds)) {
            throw new \Exception('First value must be an array.');
        }
        $keys = array();
        foreach ($objectIds as $objectId) {
            $arguments['id'] = $objectId;
            $key             = $this->makeKey($arguments);
            $keys[$key]      = $objectId;
        }
        return $keys;
    }
716646
public function addColumn($key,$args = null)
    {
        if ($key instanceof Column) {
            $args = $key->getColumnArray();
            $key = $key->name;
        }
        if (array_key_exists($key,$this->columns))
            trigger_error(sprintf(self::TEXT_ColumnExists,$key),E_USER_ERROR);
        $column = new Column($key, $this);
        if ($args)
            foreach ($args as $arg => $val)
                $column->{$arg} = $val;
        // skip default pkey field
        if (count($this->pkeys) == 1 && in_array($key,$this->pkeys))
            return $column;
        return $this->columns[$key] =& $column;
    }
1228150
protected function register(array $args)
    {
        array_walk($args, function (array $value, string $key) {
            \genesis_register_layout($key, $value);
        });
    }
301992
public function beforeUpdate(array &$args) {
        $data = &$args[1];
        $where = $args[2];
        $authVars = Garp_Auth::getInstance()->getConfigValues('validateemail');

        // Check if the email address is about to be changed, and wether we should respond to it
        if ((!empty($authVars['enabled']) && $authVars['enabled']) 
            && array_key_exists('email', $data)
        ) {
            // Collect the current email addresses to see if they are to be changed
            // @todo For now we assume that email is a unique value. This means that
            // we use fetchRow instead of fetchAll.
            // If this ever changes, fix this code.
            $user = $this->fetchRow(
                $this->select()->from($this->getName(), array('email'))->where($where)
            );
            if ($user && $user->email != $data['email']) {
                $this->_validateEmail = true;
            }
        }

        if (array_key_exists(self::IMAGE_URL_COLUMN, $data)) {
            // Allow passing in of image URLs. These are downloaded and added as image_id
            $data['image_id'] = $this->_grabRemoteImage($data[self::IMAGE_URL_COLUMN]);
            unset($data[self::IMAGE_URL_COLUMN]);
        }

        // A password might be passed in, and needs to be passed to Model_AuthLocal
        if (!empty($data[self::PASSWORD_COLUMN])) {
            // $primaryKey = $this->info(self::PRIMARY);
            // @note 'id' is the only valid primary key here. This might not be flexible enough
            // in the future, in that case, use $this->info(self::PRIMARY) to fetch the primary key.
            $primaryKey = 'id';
            // Find all matches and create or update an AuthLocal record for them.
            $matchedRecords = $this->fetchAll(
                $this->select()->from($this->getName(), array($primaryKey))->where($where)
            );

            foreach ($matchedRecords as $matchedRecord) {
                $thePrimaryKey = $matchedRecord->{$primaryKey};
                $authLocalModel = new Model_AuthLocal();
                // Check if an AuthLocal record already exists
                $authLocalRecord = $authLocalModel->fetchRow(
                    $authLocalModel->select()->where('user_id = ?', $thePrimaryKey)
                );
                // If not, create a new one
                if (!$authLocalRecord) {
                    $authLocalModel->insert(
                        array(
                        'user_id' => $thePrimaryKey,
                        'password' => $data[self::PASSWORD_COLUMN]
                        )
                    );
                } else {
                    $authLocalRecord->{self::PASSWORD_COLUMN} = $data[self::PASSWORD_COLUMN];
                    $authLocalRecord->save();
                }
            }

            // Remove the password key from the data to prevent an error
            unset($data[self::PASSWORD_COLUMN]);
        }

        // If the role is not part of the data, fetch it live
        if (empty($data[self::ROLE_COLUMN])) {
            $rows = $this->fetchAll($where);
            foreach ($rows as $row) {
                if (!$this->_isRoleAllowed($row->{self::ROLE_COLUMN})) {
                    throw new Garp_Model_Exception(self::EXCEPTION_CANNOT_EDIT_GREATER_ROLE);
                }
            }
        } else {
            // Prevent admins from saving a user's role greater than their own.
            if (!$this->_isRoleAllowed($data[self::ROLE_COLUMN])) {
                throw new Garp_Model_Exception(self::EXCEPTION_CANNOT_EDIT_GREATER_ROLE);
            }
        }
    }
396030
public function postLoad($args)
    {
        $entity = $args->getEntity();

        if (false === ($entity instanceof HasEncryptedFieldsEntityInterface) && false === ($entity instanceof EncryptedEntityInterface)) {
            return false;
        }

        $properties = $this->getEntityEncryptionReflectionProperties($entity);
        foreach ($properties as $property) {
            $fieldValue = $property->getValue($entity);

            if (null === $fieldValue || true === empty($fieldValue)) {
                continue;
            }

            /** @var Encryption $annotation */
            $annotation = DoctrineHelper::getPropertyAnnotation($property, Encryption::class, $this->getReader());

            $property->setValue($entity, OpenSSLHelper::decrypt($fieldValue, $this->getEncryptionKey(), $annotation->cipher));
        }

        /*
         * Deprecated usage
         */
        if (0 === count($properties)) {
            foreach ($this->getEntityEncryptedReflectionProperties($entity) as $property) {
                $fieldValue = $property->getValue($entity);

                if (null === $fieldValue || true === empty($fieldValue)) {
                    continue;
                }

                $property->setValue($entity, CryptUtility::decrypt($fieldValue, $this->getEncryptionKey()));
            }
        }

        return true;
    }
897482
public function preProcessAuthenticate(array $args)
    {

        $args      = $args[0];
        $signature = isset($args->signature) ? $args->signature : null;
        $extra     = isset($args->extra) ? $args->extra : null;

        if (!$signature) {
            return ['ERROR'];
        }

        return $this->processAuthenticate($signature, $extra);
    }
858969
protected function injectVariables(array $args)
    {
        if (empty($args)) {
            return;
        }

        $parser = $this->parserFactory(__METHOD__);

        foreach ($args as $name => $strValue) {
            if ($name[0] === '$') {
                $name = substr($name, 1);
            }

            if (! $parser->parseValue($strValue, $value)) {
                $value = $this->coerceValue($strValue);
            }

            $this->set($name, $value);
        }
    }
1128137
public static function escape(array $args): string
  {
    $command = '';
    foreach ($args as $arg)
    {
      if ($command!='') $command .= ' ';
      $command .= escapeshellarg($arg);
    }

    return $command;
  }