Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SodiumChachaIetfTest.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
13 
14 class SodiumChachaIetfTest extends \PHPUnit\Framework\TestCase
15 {
16  public function getCryptData(): array
17  {
18  $fixturesFilename = __DIR__ . '/../Crypt/_files/_sodium_chachaieft_fixtures.php';
19 
20  $result = include $fixturesFilename;
21  /* Restore encoded string back to binary */
22  foreach ($result as &$cryptParams) {
23  $cryptParams['encrypted'] = base64_decode($cryptParams['encrypted']);
24  }
25  unset($cryptParams);
26 
27  return $result;
28  }
29 
33  public function testEncrypt(string $key, string $encrypted, string $decrypted)
34  {
35  $crypt = new \Magento\Framework\Encryption\Adapter\SodiumChachaIetf($key);
36  $result = $crypt->encrypt($decrypted);
37 
38  $this->assertNotEquals($encrypted, $result);
39  }
40 
44  public function testDecrypt(string $key, string $encrypted, string $decrypted)
45  {
46  $crypt = new \Magento\Framework\Encryption\Adapter\SodiumChachaIetf($key);
47  $result = $crypt->decrypt($encrypted);
48 
49  $this->assertEquals($decrypted, $result);
50  }
51 }
testDecrypt(string $key, string $encrypted, string $decrypted)
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
testEncrypt(string $key, string $encrypted, string $decrypted)