473,394 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to display decrypted AES in php form

1
I have a form that I use php to retrieve data from MySQL and display that data in an input box. One of the fields is encrypted when the data is submitted into MySQL using AES_ENCRYPTED and that part works fine, I can see in the DB that that data is encrypted.
My issue is how to use AES_DECRYPT to display the decrypted data in my input box with my php code. For example my form has a field like this <input type="text" name="data" value="<?php echo $data2['data']?>"/> <--- This field being the encrypted data that I need to decrypted and display as it's original info.
I know that I can enter this at a MySQL command line SELECT aes_decrypt(data, '123456790abcdefghijklmnopqrstuvwxyz') FROM applications WHERE ID = '52' and it will display the data for record 52 decrypted I just don't know how to implement it in my php form.
I've tried this:
$data = "SELECT * FROM $tbl_name WHERE ID = $id";
$query = mysqli_query($conn, $data);
$data2 = mysqli_fetch_array($query);
and obviously it doesn't decrypt but it does show the encrypted data in the form.
I tried different variations of SELECT AES_DECRYPT('data', '$aeskey') FROM $tbl_name WHERE ID = $id"; and so on with no success.
I've tried to change the input value to value="<?php echo $data2[AES_DECRYPT('data', '$aeskey')]?>"/> and I get an empty input box.

Can someone help me get this solved PLEASE?
Oct 24 '17 #1
1 2266
Luuk
1,047 Expert 1GB
My experience with PHP is limited, but this example shows a working INSERT and SELECT

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $server = "localhost";
  3. $user = "root";
  4. $pass = "secret";
  5. $db = "test";
  6. $mysqli = mysqli_connect($server, $user, $pass, $db);
  7.  
  8. $aeskey = "12345abcde";
  9. $testvalue = "sometestvalue";
  10.  
  11. $stmt =  $mysqli->stmt_init();
  12. $stmt->prepare("drop table if exists aes");
  13. $stmt->execute();
  14. $stmt->fetch();
  15. $stmt->close();
  16.  
  17. $stmt =  $mysqli->stmt_init();
  18. $stmt->prepare("create table aes(value blob)");
  19. $stmt->execute();
  20. $stmt->fetch();
  21. $stmt->close();
  22. echo "Table 'aes' created\n";
  23.  
  24. $stmt =  $mysqli->stmt_init();
  25. if ($stmt->prepare("INSERT INTO aes VALUES(AES_ENCRYPT(?,?))")) {
  26.     $stmt->bind_param("ss", $testvalue, $aeskey);
  27.     $stmt->execute();
  28.     $stmt->close();
  29. }
  30. echo "Record inserted\n";
  31.  
  32. $stmt =  $mysqli->stmt_init();
  33. if ($stmt->prepare("SELECT AES_DECRYPT(value, ?) FROM aes")) {
  34.     $stmt->bind_param("s", $aeskey);
  35.     $stmt->execute();
  36.     $stmt->bind_result($value);
  37.     $stmt->fetch();
  38.     $stmt->close();
  39. }
  40. echo "Your testvalue is: $value\n";
  41.  
  42. $mysqli->close();
  43.  
The output is:
Table 'aes' created
Record inserted
Your testvalue is: sometestvalue
Oct 28 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Nick | last post by:
Hi, I am tring to display a form that does not show in either the task bar or when the user alt-tabs. The form is running full screen and is set to have no border. Nick
1
by: Mr Utkal Ranjan Pradhan | last post by:
Hi Friends I want to develop a windows service application, which will open a port on the machine and constantly it will listen from that port. And when any data comes to that port I want to...
2
by: Bernie Yaeger | last post by:
I have developed a .dll to display a form that controls a simple routine. Oddly, you can't use messagebox.show unless you do one of two things: either use an imports system.windows.forms or...
3
by: Brett Romero | last post by:
My application start like this: frmMaster MainForm = new frmMaster(); System.Windows.Forms.Application.Run(MainForm); The flow is that MainForm shows then a SecondForm shows after the user...
0
by: yasker | last post by:
Hi, I got a problem in display a sub form. My app contains two form: main and sub. I want sub form display before main form, to provide some information to it. I use a NotifyIcon to activity...
5
by: Paul | last post by:
Is it possible to display a form inside another form? What component should I use?
4
ak1dnar
by: ak1dnar | last post by:
I need to display a form dynamically. First i load the page and at that time Login button will display. Nothing else. If some clicks the Login button, then only I want to display the Form. So...
1
by: Zaher Rabah | last post by:
How can I display a form in dialog mode by press any keys in the keybaord in access 2003. This form is used as calculater "For fast calculate" This is the idea.
1
by: menyki | last post by:
am designing a software. in the software i want the splash to display for sometime, say 1 minute then it will close and the main form will come up. i included timer control in the splash form i...
0
by: raza rizwan | last post by:
how to display submit form select field onther page... like as a image format.... and show select filed image... Plz help.... <form action="http://example.com/submit.php" method="post"...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.