Ejemplo n.º 1
0
<?php

error_reporting(E_ALL | E_STRICT);
include dirname(__FILE__) . "/../phpCrypt.php";
use PHP_Crypt\PHP_Crypt;
$text = "This is my secret message.";
$key = "^mY@TEst~Key_0123456789abcefghij";
/**
 * Cipher: ARC4
 * Mode: Stream
 */
$crypt = new PHP_Crypt($key, PHP_Crypt::CIPHER_ARC4, PHP_Crypt::MODE_STREAM);
//$iv = $crypt->createIV(); // STREAM CIPHERS DO NOT REQUIRE AN IV FOR THE STREAM MODE
$encrypt = $crypt->encrypt($text);
$decrypt = $crypt->decrypt($encrypt);
print "CIPHER: " . $crypt->cipherName() . "\n";
print "MODE: " . $crypt->modeName() . "\n";
print "PLAIN TEXT: {$text}\n";
print "PLAIN TEXT HEX: " . bin2hex($text) . "\n";
print "ENCRYPTED HEX: " . bin2hex($encrypt) . "\n";
print "DECRYPTED: {$decrypt}\n";
print "DECRYPTED HEX: " . bin2hex($decrypt) . "\n";
Ejemplo n.º 2
0
$phpcrypt_mode = PHP_Crypt::MODE_CBC;
// END MODIFYING
/****************************************************************
 * DO NOT EDIT BELOW THIS LINE
 ****************************************************************/
// MCRYPT SETUP
srand((double) microtime() * 1000000);
//for sake of MCRYPT_RAND
$td = mcrypt_module_open($mcrypt_cipher, '', $mcrypt_mode, '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
// PHPCRYPT SETUP
$phpcrypt = new PHP_Crypt($key, $phpcrypt_cipher, $phpcrypt_mode);
print "MCRYPT: {$mcrypt_cipher} - {$mcrypt_mode}\n";
print "PHPCRYPT: " . $phpcrypt->cipherName() . " - " . $phpcrypt->modeName() . "\n\n";
/**
 * ENCRYPT USING mCrypt
 * DECRYPT USING phpCrypt
 */
// MCRYPT: ENCRYPT
mcrypt_generic_init($td, $key, $iv);
$ts_start = microtime(true);
$encrypt = mcrypt_generic($td, $text);
$m_time = number_format(microtime(true) - $ts_start, 5);
mcrypt_generic_deinit($td);
// PHPCRYPT: DECRYPT
$phpcrypt->IV($iv);
$ts_start = microtime(true);
$decrypt = $phpcrypt->decrypt($encrypt);
$p_time = number_format(microtime(true) - $ts_start, 5);