解密来自MySQL数据库的数据

解密来自MySQL数据库的数据

本文介绍了解密来自MySQL数据库的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码来显示来自HTMl数据库中MySQL数据库的所有数据:

 <?php 
$ result = mysqli_query($ con,SELECT * FROM Persons);
echo< table border ='1'>;
$ i = 0;
while($ row = $ result-> fetch_assoc())
{
if($ i == 0){
$ i ++;
回显< tr>;
foreach($ row as $ key => $ value){
echoth 。 $键。 < /第> 中;
}
echo< / tr>;
}
echo< tr>;
foreach($ row为$ value){
echo< td> 。 $值。 < / TD> 中;
}
echo< / tr>;
}
echo< / table>;

mysqli_close($ con);
?>

此代码正常工作,数据正确显示在表格中,我的问题是大部分数据库中的数据被加密(简单地)!

例如,这里是如何存储某人的名字 5cGs + mhdNN / SnHdqEbMk6zlKRu8uW7pR1zRjQHV9DGQ =

有没有办法在数据显示之前解密数据?



我通常按​​以下方式对日期进行清理:

  $ name_firstD = simple_decrypt($ name_first,secured); 


解决方案

您需要有一列加密的列<$ p
$ b

 <?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 ++;
回显< tr>;
foreach($ row as $ key => $ value){
echoth 。 $键。 < /第> 中;
}
echo< / tr>;
}
echo< tr>;
foreach($ row为$ key => $ value){
echo< td> 。 (in_array($键,$ encrypted_columns))? simple_decrypt($ value,secured):$ value。 < / TD> 中;
}
echo< / tr>;
}
echo< / table>;

mysqli_close($ con);
?>

将加密列的名称放在$ encrypted_columns数组中。


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");
解决方案

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.

这篇关于解密来自MySQL数据库的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 07:17