added encryption

This commit is contained in:
tracer 2022-09-22 19:31:38 +02:00
parent be6402b4a3
commit 4c80ba1543
1 changed files with 38 additions and 30 deletions

View File

@ -2,6 +2,11 @@
namespace App\Entity;
use App\Controller\ConfigController;
use App\Controller\EncryptionController;
use Exception;
use SodiumException;
/**
*
*/
@ -12,22 +17,45 @@ class Panel
* @param int $id
* @param string $a
* @param string $aaaa
* @param string $passphrase
* @param string $apikey
* @param string $apikeyPrefix
* @param string $self
*/
public function __construct(
private string $name,
private int $id = 0,
private string $a = '',
private string $aaaa = '',
private string $apikey = '',
private string $apikeyPrefix = '',
private string $self = 'no',
private string $name,
private int $id = 0,
private string $a = '',
private string $aaaa = '',
private readonly string $passphrase = '',
private string $apikey = '',
private string $apikeyPrefix = '',
private string $self = 'no',
)
{}
{
if ($this->passphrase) {
$configController = new ConfigController();
$encryptionController = new EncryptionController();
$encryptionKey = $configController->getConfig(configKey: 'encryptionKey');
$this->apikeyPrefix = strtok(string: $this->passphrase, token: '.');
try {
$this->apikey = $encryptionController->safeEncrypt(message: $this->passphrase, key: $encryptionKey);
} catch (Exception|SodiumException $e) {
die($e->getMessage() . PHP_EOL);
}
}
}
/**
* @return string
*/
public function getPassphrase(): string
{
return $this->passphrase;
}
/**
@ -88,7 +116,6 @@ class Panel
}
/**
* @return string
*/
@ -102,21 +129,10 @@ class Panel
*/
public function getApikey(): string
{
return $this->apikey;
}
/**
* @param string $apikey
*/
public function setApikey(string $apikey): void
{
$this->apikey = $apikey;
return $this->apikey;
}
/**
* @param string $a
*/
@ -142,12 +158,4 @@ class Panel
return $this->apikeyPrefix;
}
/**
* @param string $apikeyPrefix
*/
public function setApikeyPrefix(string $apikeyPrefix): void
{
$this->apikeyPrefix = $apikeyPrefix;
}
}