Re: ENCODE / AES / DES-Performance
I wrote a small script and run a test: AES is the fastest method according to it (note: I only looked at DECRYPTing performance)
Here are the results of 100,000 decrypts:
DECODE: 13,516secs.
AES_DECRYPT: 8,614secs.
DES_DECRYPT: 11,559secs.
Here is the script if you want to run it on your own:
---------- snip ### cryptbench.php ----------------
## Cryptbench
## written by: xxxxxxxxxxxxxxxxxxxxxxx
## Aug 06 2005
<?PHP
$mysqli= mysqli_connect("localhost","root","myebs20");
/* check connection */
if (!$mysqli) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
printf("Host information: %s\n", mysqli_get_host_info($mysqli));
$text='testkeytobeencrypted';
$key='testkey';
$eachruns=100000;
echo "\n Generating ENCODING for '$text' with key: $key >> ";
$result=mysqli_query($mysqli,"SELECT ENCODE('$text','$key');");
$row = mysqli_fetch_array($result, MYSQLI_NUM);
$encode=$row[0];
echo "$encode \n";
echo "Starting benchmarking $eachruns decodings now\n";
$time_start=microtime(1);
for ($i=0; $i<$eachruns; $i++) {
mysqli_query($mysqli,"SELECT DECODE('$encode','$key');");
}
$time_end = microtime(1);
$time=$time_end-$time_start;
$result=mysqli_query($mysqli,"SELECT DECODE('$encode','$key');");
$row = mysqli_fetch_array($result, MYSQLI_NUM);
$decoded=$row[0];
echo "Took $time secs. to decode '$decoded' $eachruns times.\n\n";
echo "\n Generating AES_ENCRYPT for '$text' with key: $key >> ";
$result=mysqli_query($mysqli,"SELECT AES_ENCRYPT('$text','$key');");
$row = mysqli_fetch_array($result, MYSQLI_NUM);
$aes_encrypt=$row[0];
echo "$aes_encrypt \n";
echo "Starting benchmarking $eachruns aes_decrypts now\n";
$time_start=microtime(1);
for ($i=0; $i<$eachruns; $i++) {
mysqli_query($mysqli,"SELECT AES_DECRYPT('$aes_encrypt','$key');");
}
$time_end = microtime(1);
$time=$time_end-$time_start;
$result=mysqli_query($mysqli,"SELECT AES_DECRYPT('$aes_encrypt','$key');");
$row = mysqli_fetch_array($result, MYSQLI_NUM);
$aes_decrypt=$row[0];
echo "Took $time secs. to decode '$aes_decrypt' $eachruns times.\n\n";
echo "\n Generating DES_ENCRYPT for '$text' with key: $key >> ";
$result=mysqli_query($mysqli,"SELECT DES_ENCRYPT('$text','$key');");
$row = mysqli_fetch_array($result, MYSQLI_NUM);
$des_encrypt=$row[0];
echo "$des_encrypt \n";
echo "Starting benchmarking $eachruns des_decrypts now\n";
$time_start=microtime(1);
for ($i=0; $i<$eachruns; $i++) {
mysqli_query($mysqli,"SELECT DES_DECRYPT('$des_encrypt','$key');");
}
$time_end = microtime(1);
$time=$time_end-$time_start;
$result=mysqli_query($mysqli,"SELECT DES_DECRYPT('$des_encrypt','$key');");
$row = mysqli_fetch_array($result, MYSQLI_NUM);
$des_decrypt=$row[0];
echo "Took $time secs. to decode '$des_decrypt' $eachruns times.\n\n";
/* close connection */
mysqli_close($mysqli);
?>
Edited 1 time(s). Last edit at 08/15/2005 11:11AM by Edwin DeSouza.