Skip to content
This repository was archived by the owner on Jan 22, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions tests/Bitpay/Crypto/McryptExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,41 @@ public function testHasSupport()
$this->assertSame(extension_loaded('mcrypt'), $mcrypt->hasSupport());
}

public function testEncryptAndDecrypt()
public function testEncrypt()
{

$mcrypt = new McryptExtension();
$key = 'testEncrypt';
$data = array(
'lsdkjflaslkfslj' => 'kz2DG4D3vkA6bkDbhrvD+Q==',
'a340932084093280' => 'gNaNgXFc7ecle8SaAJAJOw==',
'*&($*@*%&*$*#*&@(*#*(' => 'cVGF2lnyH6OHLYWHa+8XxHbFzVNK5IYL',
'___asdfa234($*(#__' => 'I8OFg5parn9b0Qk8mJnQH0+SgQWwYER5'
);

$this->assertNotNull($mcrypt);

for ($i=1; $i<=20; $i++) {
$plaintext = $this->generateRandomString($i);
$key = $this->generateRandomString(8);
foreach($data as $unencrypted => $encrypted )
{
$encryptedtext = $mcrypt->encrypt($unencrypted, $key, '00000000');
$this->assertEquals($encrypted, $encryptedtext);
}
}

$iv_size = $mcrypt->getIVSize();
$iv = mcrypt_create_iv($iv_size);
public function testDecrypt()
{

$encryptedtext = $mcrypt->encrypt($plaintext, $key, $iv);
$this->assertNotEquals($plaintext, $encryptedtext);
$mcrypt = new McryptExtension();
$key = 'testEncrypt';
$data = array(
'lsdkjflaslkfslj' => 'kz2DG4D3vkA6bkDbhrvD+Q==',
'a340932084093280' => 'gNaNgXFc7ecle8SaAJAJOw==',
'*&($*@*%&*$*#*&@(*#*(' => 'cVGF2lnyH6OHLYWHa+8XxHbFzVNK5IYL',
'___asdfa234($*(#__' => 'I8OFg5parn9b0Qk8mJnQH0+SgQWwYER5'
);

$decryptedtext = $mcrypt->decrypt($encryptedtext, $key, $iv);
$this->assertEquals($plaintext, $decryptedtext);
foreach($data as $unencrypted => $encrypted )
{
$plaintext = $mcrypt->decrypt($encrypted, $key, '00000000');
$this->assertEquals($unencrypted, $plaintext);
}
}

Expand Down