dtwr2012 2016-09-22 09:00
浏览 36
已采纳

如何在foreach循环中解密变量?

The following code loops my decryption I have no idea how to decrypt each inner['post_text'].

https://gyazo.com/672cd615b86b3c107da7e2c386d3b2f9

if (!empty($_SESSION['room_id'])) {
    $getPosts = $verbinding->prepare("SELECT user_name, post_text FROM posts WHERE room_id = :room_id");
    $getPosts->bindParam(':room_id', $_SESSION['room_id']);
    $getPosts->execute();
    $posts = $getPosts->fetchAll(PDO::FETCH_ASSOC);
    foreach ($posts as $inner) {
        $username = $inner['user_name'];
        $text = $inner['post_text'];
        $um = "@4um:~$";
        echo "<br><div class = \"posts\">" . $username . "$um&nbsp" . decr($text) . " </div>";
    }

}

function decr($text){
    $iterations = 1;
    $salt = mcrypt_create_iv(16, MCRYPT_DEV_URANDOM);
    $text = hash_pbkdf2("sha512", $text, $salt, $iterations, 512);
    echo $text;
}
  • 写回答

2条回答 默认 最新

  • douwo1862 2016-09-22 10:02
    关注

    As stated in the comments you cannot decrypt a hash. For that you need to use an encryption algorithm, using mcrypt_encrypt() before saving and mcrypt_decrypt() when displaying.

    Seeing as you've already hashed your content, there is no way to get it back. You need to start over, and delete all of the old content, in order to do what you're looking to do.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 comsol温度场仿真无法模拟微米级激光光斑
  • ¥15 上传图片时提交的存储类型
  • ¥15 Ubuntu开机显示器只显示kernel,是没操作系统(相关搜索:显卡驱动)
  • ¥15 VB.NET如何绘制倾斜的椭圆
  • ¥15 在rhel8中安装qemu-kvm时遇到“cannot initialize crypto:unable to initialize gcrypt“报错”
  • ¥15 arbotix没有/cmd_vel话题
  • ¥20 找能定制Python脚本的
  • ¥15 odoo17的分包重新供应路线如何设置?可从销售订单中实时直接触发采购订单或相关单据
  • ¥15 用C语言怎么判断字符串的输入是否符合设定?
  • ¥15 通信专业本科生论文选这两个哪个方向好研究呀