UPDATE
I found a problem that supported my script. Apparently this had nothing to do with decryption, but instead I redirected. When I delete this block of code, the script starts to execute quickly. Still not sure why this caused the problem?
// Make sure we have an Order ID if( ! isset($_GET['id']) && ! isset($_POST['id']) ) { header("Location: https://www.website.com/orders/"); exit; }
ORIGINAL QUESTION:
I use the Encryption class, which can be found here: Encryption class . I store data in a MySQL database with the binary data type VARCHAR (I tried BLOB and TINYBLOB earlier).
Encryption and decryption both work, but it takes 1 minute to decrypt. Encryption is fast.
I think I should also say that this happens via the https connection (in case it is relevant).
I do not remember it lasting long to decrypt. Do you have any ideas what might be causing this? When I comment out part of the decryption of the PHP code and just return the encrypted string, it runs quickly.
CODE PROHIBITED BELOW IN COMMENT
class Encryption { const CYPHER = 'blowfish'; const MODE = 'cfb'; const KEY = 'MyPersonalKey'; public function encrypt($plaintext) { $td = mcrypt_module_open(self::CYPHER, '', self::MODE, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, self::KEY, $iv); $crypttext = mcrypt_generic($td, $plaintext); mcrypt_generic_deinit($td); return $iv.$crypttext; } public function decrypt($crypttext) { $plaintext = ''; $td = mcrypt_module_open(self::CYPHER, '', self::MODE, ''); $ivsize = mcrypt_enc_get_iv_size($td); $iv = substr($crypttext, 0, $ivsize); $crypttext = substr($crypttext, $ivsize); if ($iv) { mcrypt_generic_init($td, self::KEY, $iv); $plaintext = mdecrypt_generic($td, $crypttext); } return $plaintext; } }
Here is the code from the webpage where I set the variables from the MySQL string. I am using the Wordpress $ wpdb object.
$order = $wpdb->get_row("SELECT * FROM orders WHERE id = ".$order_id." LIMIT 0,1"); $addons_price = $order->addons_price; $hooked_package = (isset($_GET['hooked_package'])) ? $_GET['hooked_package'] : $order->hooked_package; $arrival_date_unix = $order->arrival_date_unix; $order_data = unserialize($order->order_data); $preview_total = $order_data['preview_price'] + $addons_price + $order_data['travel_insurance']; $normal_total = $order_data['normal_price'] + $addons_price + $order_data['travel_insurance']; $package_price = $order->package_price; $total_price = $order->total_price; $billing_cc = Encryption::decrypt($order->billing_cc);
Also, here is the MySQL type ...
`billing_cc` varbinary(255) DEFAULT NULL