Decrypt data from MySQL database

点点圈 提交于 2019-12-12 05:08:16

问题


I have the below code to show all data from a MySQL database in a HTMl database:

<?php
$result = mysqli_query($con,"SELECT * FROM Persons");
echo "<table border='1'>";
$i = 0;
while($row = $result->fetch_assoc())
{
    if ($i == 0) {
      $i++;
      echo "<tr>";
      foreach ($row as $key => $value) {
        echo "<th>" . $key . "</th>";
      }
      echo "</tr>";
    }
    echo "<tr>";
    foreach ($row as $value) {
      echo "<td>" . $value . "</td>";
    }
    echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

This code works fine and the data is displayed in the table correctly, my problem is that most of the data in the DB is encrypted (simply)!

For example, here is how someones first name is stored 5cGs+mhdNN/SnHdqEbMk6zlKRu8uW7pR1zRjQHV9DGQ=

Is there a way to decrypt the data before displaying it in the table?

I usually decrpyt the date in the following way:

$name_firstD = simple_decrypt($name_first , "secured");

回答1:


You need to have an array of columns which are encrypted.

<?php
$result = mysqli_query($con,"SELECT * FROM Persons");

$encrypted_columns = array('password','code', 'first_name');

echo "<table border='1'>";
$i = 0;
while($row = $result->fetch_assoc())
{
    if ($i == 0) {
      $i++;
      echo "<tr>";
      foreach ($row as $key => $value) {
        echo "<th>" . $key . "</th>";
      }
      echo "</tr>";
    }
    echo "<tr>";
    foreach ($row as $key => $value) {
      echo "<td>" . (in_array($key,$encrypted_columns))? simple_decrypt($value , "secured") : $value . "</td>";
    }
    echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

put the name of your encrypted column inside $encrypted_columns array.



来源:https://stackoverflow.com/questions/37575004/decrypt-data-from-mysql-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!