Browse Source

Encryption tests

tags/0.0.7
Anton Smirnov 4 weeks ago
parent
commit
500e1c7962
1 changed files with 39 additions and 0 deletions
  1. 39
    0
      tests/EncryptV2Test.php

+ 39
- 0
tests/EncryptV2Test.php View File

@@ -0,0 +1,39 @@
<?php

use PHPUnit\Framework\TestCase;
use SandFox\Encryptor\Algo\V2\Decrypt;
use SandFox\Encryptor\Algo\V2\Encrypt;
use SandFox\Encryptor\Secret\Key;
use SandFox\Encryptor\Secret\Password;

class EncryptV2Test extends TestCase
{
use TestData;

public function testEncryptWithPassword()
{
$decrypted = $this->getDecrypted();
$password = $this->getPassword();
$secret = new Password($password);
$encryptor = new Encrypt();
$decryptor = new Decrypt();
foreach (range(1, 3) as $strength) {
$secret->setStrength($strength);
$encrypted = $encryptor->encrypt($decrypted, $secret);
$decrypted2 = $decryptor->decrypt($encrypted, $secret);
$this->assertEquals($decrypted, $decrypted2);
}
}

public function testEncryptWithKey()
{
$decrypted = $this->getDecrypted();
$encryptor = new Encrypt();
$decryptor = new Decrypt();
$key = $this->getKey_V2_S2();
$secret = new Key($key);
$encrypted = $encryptor->encrypt($decrypted, $secret);
$decrypted2 = $decryptor->decrypt($encrypted, $secret);
$this->assertEquals($decrypted, $decrypted2);
}
}

Loading…
Cancel
Save