Fix for Symmetric encryption key handling

This commit is contained in:
Clemens Schwaighofer
2024-12-12 21:11:25 +09:00
parent 346cdaad72
commit fbea8f4aca
2 changed files with 172 additions and 3 deletions

View File

@@ -49,7 +49,11 @@ class SymmetricEncryption
*/
public static function getInstance(string|null $key = null): self
{
if (empty(self::$instance)) {
// new if no instsance or key is different
if (
empty(self::$instance) ||
self::$instance->key != $key
) {
self::$instance = new self($key);
}
return self::$instance;
@@ -130,7 +134,7 @@ class SymmetricEncryption
*/
private function encryptData(string $message, ?string $key): string
{
if (empty($this->key) || $key === null) {
if ($key === null) {
throw new \UnexpectedValueException('Key not set');
}
$key = $this->createKey($key);