MySQL AES decryption problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

MySQL AES decryption problem

Post by cap2cap10 »

Hello, again members of the PHP Technorati! I come to you with a pressing problem concerning AES decryption script. it is not returning any value, hence resulting in a Notice: unidentified variable error for all array values. Here is the code: :banghead:

Code: Select all

mysql_select_db('mdo_db');
 $query = "SELECT AES_DECRYPT(c_f_lbl_1, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_2, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_3, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_4, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_5, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_6, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_7, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_8, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_9, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_10, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_11, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_12, '.$fvek_1.'),
 AES_DECRYPT(c_f_lbl_13, '.$fvek_1.')
 FROM `form_tbl` WHERE `form_id` = 757577554";

 $result =  mysql_query($query) or die(mysql_error());
 $get_form = mysql_fetch_array($result);

$get_form['c_f_lbl_1'] = $c_f_lbl_1;
$c_f_lbl_2 = $get_form['c_f_lbl_2'];
$c_f_lbl_3 = $get_form['c_f_lbl_3'];
$c_f_lbl_4 = $get_form['c_f_lbl_4'];
$c_f_lbl_5 = $get_form['c_f_lbl_5'];
$c_f_lbl_6 = $get_form['c_f_lbl_6'];
$c_f_lbl_7 = $get_form['c_f_lbl_7'];
$c_f_lbl_8 = $get_form['c_f_lbl_8'];
$c_f_lbl_9 = $get_form['c_f_lbl_9'];
$c_f_lbl_10 = $get_form['c_f_lbl_10'];
$c_f_lbl_11 = $get_form['c_f_lbl_11'];
$c_f_lbl_12 = $get_form['c_f_lbl_12'];
$c_f_lbl_13 = $get_form['c_f_lbl_13'];

I suspect that the decrypt is yielding an empty array of values. Please enlighten me as to the error of my ways.
Thanks in advance,

Batoe
Last edited by requinix on Fri Jan 23, 2015 4:30 pm, edited 1 time in total.
Reason: removing odd bbcode that doesn't belong
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: MySQL AES decryption problem

Post by requinix »

The AES_DECRYPT() calls don't preserve the name of the column in the returned data. True for actually every time you use an expression in there.
Without giving them explicit aliases you'd have to look for

Code: Select all

$get_form['AES-DECRYPT(c_f_lbl_2, ' . $fvek_1 . ')']
which is silly so you should use aliases.

Code: Select all

 $query = "SELECT AES_DECRYPT(c_f_lbl_1, '.$fvek_1.') AS c_f_lbl_1,
 AES_DECRYPT(c_f_lbl_2, '.$fvek_1.') AS c_f_lbl_2,
 AES_DECRYPT(c_f_lbl_3, '.$fvek_1.') AS c_f_lbl_3,
 AES_DECRYPT(c_f_lbl_4, '.$fvek_1.') AS c_f_lbl_4,
 AES_DECRYPT(c_f_lbl_5, '.$fvek_1.') AS c_f_lbl_5,
 AES_DECRYPT(c_f_lbl_6, '.$fvek_1.') AS c_f_lbl_6,
 AES_DECRYPT(c_f_lbl_7, '.$fvek_1.') AS c_f_lbl_7,
 AES_DECRYPT(c_f_lbl_8, '.$fvek_1.') AS c_f_lbl_8,
 AES_DECRYPT(c_f_lbl_9, '.$fvek_1.') AS c_f_lbl_9,
 AES_DECRYPT(c_f_lbl_10, '.$fvek_1.') AS c_f_lbl_10,
 AES_DECRYPT(c_f_lbl_11, '.$fvek_1.') AS c_f_lbl_11,
 AES_DECRYPT(c_f_lbl_12, '.$fvek_1.') AS c_f_lbl_12,
 AES_DECRYPT(c_f_lbl_13, '.$fvek_1.') AS c_f_lbl_13
 FROM `form_tbl` WHERE `form_id` = 757577554";
Side note: are you sure

Code: Select all

$get_form['c_f_lbl_1'] = $c_f_lbl_1;
isn't backwards?
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

Re: MySQL AES decryption problem

Post by cap2cap10 »

:drunk: Outstanding! another syntax error fiasco thwarted by the Technorati. Anyone know about AES256 implementation?
AES by itself is acceptable, but it would be nice to improve one's level of security with a stronger Encrypt.

Thanks again,

Batoe
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: MySQL AES decryption problem

Post by requinix »

AES is a bit older than some other algorithms but it's still fine to use.
Post Reply