Exemplo n.º 1
0
die;
//*/
/* Performance test */
$iterations = isset($_GET['iterations']) ? (int) $_GET['iterations'] : 1000;
$text = '1111111111111111';
$s0 = 0;
echo "<h3>Static method</h3>", "Average from {$iterations} iterations<br/>\n";
$s = microtime(true);
for ($i = 0; $i < $iterations; ++$i) {
    Aes128::encrypt($text);
    if ($i == 0) {
        $s0 = microtime(true) - $s;
    }
}
echo "Encrypting: ", (microtime(true) - $s) / $iterations, " (ms) avg; first run: {$s0} (ms)<br/>\n";
$text = Aes128::encrypt($text);
$s = microtime(true);
for ($i = 0; $i < $iterations; ++$i) {
    Aes128::decrypt($text);
    if ($i == 0) {
        $s0 = microtime(true) - $s;
    }
}
echo "Decrypting: ", (microtime(true) - $s) / $iterations, " (ms) avg; first run: {$s0} (ms)<br/>\n";
echo "<h3>Ouput testing</h3>\n";
echo Aes128::decrypt(Aes128::encrypt('1111111111111111')), "<br/>";
echo Aes128::encrypt('1111111111111111'), "<br/>";
echo var_dump(Aes128::decrypt(Aes128::encrypt('6451')));
echo "<br/>";
echo Aes128::encrypt('6451');
//*/
Exemplo n.º 2
0
 /**
  * @abstract Decrypts a string AES 128 bit into plain-text. 
  *
  * @param string $text The string to decrypt.
  * @param string $salt Optional. The string that the encryption was salted with (default: Aes128::DEFAULT_SALT).
  * @param string $iv Optional. A 16 character initialization vector (default: false).  If not provided (i.e.: false), a random 
  * IV will be generated.
  * @param bool $isHex Optional.  Whether to treat $text as a hex (true) or binary string (false) (default: true).
  * @return string the encrypted string
  */
 public static function decrypt($text, $salt = Aes128::DEFAULT_SALT, $iv = false, $isHex = true)
 {
     return mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $salt, $isHex ? pack("H*", $text) : $text, MCRYPT_MODE_ECB, Aes128::iv($iv));
 }