ImboCli\Command\GeneratePrivateKey::generate PHP Method

generate() public method

Generate a private key
public generate ( ) : string
return string
    public function generate()
    {
        $strong = false;
        $i = 0;
        while (!$strong && $this->maxTries > $i++) {
            $data = openssl_random_pseudo_bytes(32, $strong);
        }
        if (!$strong) {
            throw new RuntimeException('Could not generate private key');
        }
        // base64_encode to get a decent ascii compatible format, and trim ending ='s.
        $key = rtrim(base64_encode($data), '=');
        // We change +/ into -_ to avoid any human confusion with paths
        return strtr($key, '+/', '-_');
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Ask the user for a private key (or generate one if user does not specify)
  *
  * @param  InputInterface  $input
  * @param  OutputInterface $output
  * @return string
  */
 private function askForPrivateKey(InputInterface $input, OutputInterface $output)
 {
     $privateKeyGenerator = new GeneratePrivateKey();
     $question = new Question('What do you want the private key to be (leave blank to generate)', $privateKeyGenerator->generate());
     return $this->getHelper('question')->ask($input, $output, $question);
 }