Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more tests and implemented empty extension block
- Loading branch information
Showing
14 changed files
with
519 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
require_once 'AES256Implementation.php'; | ||
|
||
class MCryptAES256Implementation implements AES256Implementation | ||
{ | ||
const BLOCK_SIZE = 16; // 128 bits | ||
const KEY_SIZE = 32; // 256 bits | ||
const MY_MCRYPT_CIPHER = MCRYPT_RIJNDAEL_128; | ||
const MY_MCRYPT_MODE = MCRYPT_MODE_CBC; | ||
|
||
public function checkDependencies() | ||
{ | ||
$function_list = array( | ||
"mcrypt_create_iv", | ||
"mcrypt_encrypt", | ||
"mcrypt_decrypt", | ||
); | ||
foreach ($function_list as $func) { | ||
if (!function_exists($func)) { | ||
throw new Exception("Missing function dependency: " . $func); | ||
} | ||
} | ||
} | ||
|
||
public function createIV() | ||
{ | ||
return mcrypt_create_iv( self::BLOCK_SIZE, MCRYPT_RAND ); | ||
} | ||
|
||
public function createRandomKey() | ||
{ | ||
return mcrypt_create_iv( self::KEY_SIZE, MCRYPT_RAND ); | ||
} | ||
|
||
public function encryptData($the_data, $iv, $enc_key) | ||
{ | ||
return mcrypt_encrypt( self::MY_MCRYPT_CIPHER, $enc_key, $the_data , self::MY_MCRYPT_MODE , $iv ); | ||
} | ||
|
||
public function decryptData($the_data, $iv, $enc_key) | ||
{ | ||
return mcrypt_decrypt( self::MY_MCRYPT_CIPHER, $enc_key, $the_data , self::MY_MCRYPT_MODE , $iv ); | ||
} | ||
} |
Oops, something went wrong.