Skip to content

Commit 347d3fd

Browse files
committed
Make encrypt and decrypt symetric
1 parent 32bd3ce commit 347d3fd

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

lib/internal/Magento/Framework/Encryption/Adapter/Sodium.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,14 @@ class Sodium implements EncryptionAdapterInterface
1616
*/
1717
private $key;
1818

19-
/**
20-
* @var int
21-
*/
22-
private $keyVersion;
23-
2419
/**
2520
* Sodium constructor.
2621
* @param string $key
27-
* @param int|null $keyVersion
2822
*/
2923
public function __construct(
30-
string $key,
31-
int $keyVersion = null
24+
string $key
3225
) {
3326
$this->key = $key;
34-
$this->keyVersion = $keyVersion;
3527
}
3628

3729
/**
@@ -50,9 +42,7 @@ public function encrypt(string $data): string
5042
$this->key
5143
);
5244

53-
return $this->keyVersion .
54-
':' . Encryptor::CIPHER_AEAD_CHACHA20POLY1305 .
55-
':' . base64_encode($nonce . $cipherText);
45+
return $nonce . $cipherText;
5646
}
5747

5848
/**

lib/internal/Magento/Framework/Encryption/Encryptor.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,11 @@ private function getPasswordVersion()
274274
*/
275275
public function encrypt($data)
276276
{
277-
$crypt = new Sodium($this->keys[$this->keyVersion], $this->keyVersion);
277+
$crypt = new Sodium($this->keys[$this->keyVersion]);
278278

279-
return $crypt->encrypt($data);
279+
return $this->keyVersion .
280+
':' . self::CIPHER_AEAD_CHACHA20POLY1305 .
281+
':' . base64_encode($crypt->encrypt($data));
280282
}
281283

282284
/**

0 commit comments

Comments
 (0)