douchanxiu5636 2017-04-05 12:00
浏览 17
已采纳

解密值未正确显示

I am encrypting the values and sending an encrypted value on another page with the help of URL and there I am decrypting values but decrypted value is not displaying properly. I am getting output like \j3�B��9[r�m�N�B~=��:�nc.�

Would you help me in this?

Index.php

$input =5;
$encrypted = encryptIt( $input );
echo $encrypted;
function encryptIt( $q ) {
    $cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';
    $qEncoded      = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
    return( $qEncoded );
}

echo "<a href='decry.php?user_id=$encrypted'>Click here</a>";

decry.php

$id=$_GET['user_id'];
$decrypted = decryptIt( $id );
echo $decrypted;
function decryptIt( $q ) {
    $cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';
    $qDecoded      = rtrim( mcrypt_decrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), base64_decode( $q ), MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ), "\0");
    return( $qDecoded );
}
  • 写回答

1条回答 默认 最新

  • douang4294 2017-04-05 12:25
    关注

    As RiggsFolly said using urlencode(). As I tried it with different numbers it worked fine for some. While others had the problem stated above (I guess it is down the = appearing) but once I added urlencode() that fixed it!

    $input =5;
    $encrypted = encryptIt( $input );
    echo $encrypted;
    function encryptIt( $q ) {
        $cryptKey  = 'qJB0rGtIn5UB1xG03efyCp';
        $qEncoded      = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, md5( $cryptKey ), $q, MCRYPT_MODE_CBC, md5( md5( $cryptKey ) ) ) );
        return( $qEncoded );
    }
    
    echo "<a href='decry.php?user_id=".urlencode($encrypted)."'>Click here</a>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line