You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
use Dcrypt\Aes;
|
|
use Dcrypt\Mcrypt;
|
|
|
|
class AesTest extends PHPUnit_Framework_TestCase
|
|
{
|
|
|
|
public function testCrossCompatability()
|
|
{
|
|
$k = 'asdf';
|
|
$p = '1234';
|
|
$c = Aes::encrypt($p, $k);
|
|
$this->assertEquals($p, Mcrypt::decrypt($c, $k));
|
|
}
|
|
|
|
/**
|
|
* @expectedException InvalidArgumentException
|
|
*/
|
|
public function testPbkdf()
|
|
{
|
|
$input = 'AAAAAAAA';
|
|
$key = 'AAAAAAAA';
|
|
$encrypted = Aes::encrypt($input, $key, 10);
|
|
$this->assertEquals($input, Aes::decrypt($encrypted, $key, 10));
|
|
|
|
$corrupt = \Dcrypt\Support\TestSupport::swaprandbyte($encrypted);
|
|
Aes::decrypt($corrupt, $key, 10);
|
|
}
|
|
|
|
/**
|
|
* @expectedException InvalidArgumentException
|
|
*/
|
|
public function testEngine()
|
|
{
|
|
$input = 'AAAAAAAA';
|
|
$key = 'AAAAAAAA';
|
|
|
|
$encrypted = Aes::encrypt($input, $key);
|
|
$this->assertEquals($input, Aes::decrypt($encrypted, $key));
|
|
|
|
// Perform a validation by replacing a random byte to make sure
|
|
// the decryption fails. After enough successful runs,
|
|
// all areas of the cypher text will have been tested
|
|
// for integrity
|
|
$corrupt = \Dcrypt\Support\TestSupport::swaprandbyte($encrypted);
|
|
Aes::decrypt($corrupt, $key);
|
|
}
|
|
|
|
public function testVector()
|
|
{
|
|
$input = 'hello world';
|
|
$pass = 'password';
|
|
$vector = \base64_decode('eZu2DqB2gYhdA2YkjagLNJJVMVo1BbpJ75tW/PO2bGIY98XHD+Gp+YlO5cv/rHzo45LHMCxL2qOircdST1w5hg==');
|
|
|
|
$this->assertEquals($input, Aes::decrypt($vector, $pass));
|
|
}
|
|
|
|
}
|