General Question

simy202's avatar

Failed to encrypt data using PHP?

Asked by simy202 (1points) January 27th, 2011

Hi everyone,
I am in trouble now. Just tried lots of different versions of AES_ENCRYPT / AES_DECRYPT scripts but cannot get it working. I’ve even tried putting the mySQL directly in via the phpAdmin on http://www.phpkode.com/scripts/category/php-cryptography/ query window where it works fine. I generated the following code from the ‘generate php’ button on there.

Can anybody tell me what I’m doing wrong, please.

The PHP Encryption script is:

mysql_connect($dbhostname,$username,$password);
@mysql_select_db($database) or die( “databaseConnection=0”);

$query = “INSERT INTO encodeit (id,card_number) VALUES (\‘8\’,AES_ENCRYPT(\‘Anthony\’,\‘xk8\’))”;

$successful = mysql_query($query);
echo $query;
echo $successful;
mysql_close();

This generates a record in my database, but the ‘card_number’ field is a blob so I can’t view the data in there (unless someone can tell me otherwise???).

Thanks for any help in advance
Simy

Observing members: 0 Composing members: 0

1 Answer

Vortico's avatar

Instead of third party scripts, you should use the Mcrypt module to encrypt card data into a secure(ish) binary BLOB column. Although, if you choose to use MySQL-side encryption, here is the cryptography functions manual. (I assume you will be using longer than a three-character key for production.)

However, having looked at your code, I would not want to enter my card number on your site. Read about SQL injection and use the MySQL Improved Extension for secure database updates and selections.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther