|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is the Encryption test. |
| 5 | + * |
| 6 | + * @author Peter279k <peter279k@gmail.com> |
| 7 | + * @author-profile https://peterli.website/ |
| 8 | + * |
| 9 | + * For the full copyright and license information, please view the LICENSE |
| 10 | + * file that was distributed with this source code. |
| 11 | + * |
| 12 | + * @note This file is not a part of Zest Framework. |
| 13 | + * |
| 14 | + * @license MIT |
| 15 | + */ |
| 16 | + |
| 17 | +namespace Lablnet\Tests; |
| 18 | + |
| 19 | +use Lablnet\Encryption; |
| 20 | +use PHPUnit\Framework\TestCase; |
| 21 | + |
| 22 | +class EncryptionTest extends TestCase |
| 23 | +{ |
| 24 | + public function testEncryptAndDecryptWithOpenSsl() |
| 25 | + { |
| 26 | + $encryption = new Encryption('12345678990-=====-===','openssl'); |
| 27 | + $encryptedString = $encryption->encrypt('plain-text'); |
| 28 | + $decryptedString = $encryption->decrypt($encryptedString); |
| 29 | + |
| 30 | + $this->assertStringEndsWith('==', $encryptedString); |
| 31 | + $this->assertSame(80, strlen($encryptedString)); |
| 32 | + $this->assertSame('plain-text', $decryptedString); |
| 33 | + } |
| 34 | + |
| 35 | + public function testEncryptAndDecryptWithSodium() |
| 36 | + { |
| 37 | + $encryption = new Encryption('euyq74tjfdskjFDSGq74','sodium'); |
| 38 | + $encryptedString = $encryption->encrypt('plain-text'); |
| 39 | + $decryptedString = $encryption->decrypt($encryptedString); |
| 40 | + |
| 41 | + $this->assertStringEndsWith('==', $encryptedString); |
| 42 | + $this->assertSame(80, strlen($encryptedString)); |
| 43 | + $this->assertSame('plain-text', $decryptedString); |
| 44 | + } |
| 45 | +} |
0 commit comments