30 lines
894 B
PHP
30 lines
894 B
PHP
<?php
|
|
|
|
namespace App\Command;
|
|
|
|
use Spatie\Crypto\Rsa\KeyPair;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
|
|
|
#[AsCommand(name: 'app:crypto:generate-keys', description: 'Generate keypair for encryption')]
|
|
class GenerateKeysCommand extends Command
|
|
{
|
|
public function __construct(private readonly string $path)
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
(new KeyPair())->generate($this->path.'/private.key', $this->path.'/public.key');
|
|
|
|
$io = new SymfonyStyle($input, $output);
|
|
$io->success('Generated keypair in '.$this->path);
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|