Skip to content

Commit 0456e42

Browse files
committed
feat: added trait to generate keys for AES
1 parent d856275 commit 0456e42

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [v14.29.0](https://github.com/Lion-Packages/framework/compare/v14.28.1...v14.29.0) (2023-07-20)
44

5+
### Added
6+
- added trait to generate keys for AES
7+
58
### Changed
69
- output format for rules have been modified
710
- RSA route settings have been updated

app/Console/Framework/AES/NewAESCommand.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
namespace App\Console\Framework\AES;
44

5+
use App\Traits\Framework\AES;
56
use App\Traits\Framework\ConsoleOutput;
67
use Symfony\Component\Console\Command\Command;
78
use Symfony\Component\Console\Input\InputInterface;
89
use Symfony\Component\Console\Output\OutputInterface;
910

1011
class NewAESCommand extends Command {
1112

12-
use ConsoleOutput;
13+
use ConsoleOutput, AES;
1314

1415
protected static $defaultName = "aes:new";
1516

@@ -27,22 +28,8 @@ protected function configure() {
2728
}
2829

2930
protected function execute(InputInterface $input, OutputInterface $output) {
30-
$generateKeys = function() {
31-
$items = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@-_/*{}[].,#$&';
32-
$bytes = random_bytes(16);
33-
$longitud = strlen($items);
34-
$key = '';
35-
36-
for ($i = 0; $i < 16; $i++) {
37-
$indice = ord($bytes[$i]) % $longitud;
38-
$key .= $items[$indice];
39-
}
40-
41-
return $key;
42-
};
43-
44-
$output->writeln($this->warningOutput("\t>> AES KEY: {$generateKeys()}"));
45-
$output->writeln($this->warningOutput("\t>> AES IV: {$generateKeys()}"));
31+
$output->writeln($this->warningOutput("\t>> AES KEY: {$this->generateKeys()}"));
32+
$output->writeln($this->warningOutput("\t>> AES IV: {$this->generateKeys()}"));
4633
$output->writeln($this->successOutput("\t>> Keys created successfully"));
4734
return Command::SUCCESS;
4835
}

app/Console/Framework/New/TraitCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
4343
$this->force();
4444
$this->close();
4545

46-
$output->writeln($this->warningOutput("\t>> TRAIT: {$trait}"));
46+
$output->writeln($this->warningOutput("\t>> TRAIT: {$list['class']}"));
4747
$output->writeln($this->successOutput("\t>> TRAIT: The '{$list['namespace']}\\{$list['class']}' trait has been generated"));
4848
return Command::SUCCESS;
4949
}

app/Traits/Framework/AES.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Traits\Framework;
4+
5+
trait AES {
6+
7+
public function generateKeys(): string {
8+
$items = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@-_/*{}[].,#$&';
9+
$bytes = random_bytes(16);
10+
$longitud = strlen($items);
11+
$key = '';
12+
13+
for ($i = 0; $i < 16; $i++) {
14+
$indice = ord($bytes[$i]) % $longitud;
15+
$key .= $items[$indice];
16+
}
17+
18+
return $key;
19+
}
20+
21+
}

0 commit comments

Comments
 (0)