【问题标题】:php mcrypt_decrypt, base64_decode and line breakphp mcrypt_decrypt、base64_decode 和换行
【发布时间】:2014-07-27 17:41:18
【问题描述】:

如何换行?例如:
第1行
第2行
第3行
解码后的样子 -> line1 line2 line3

$key =  $_POST['key']; $input = $_POST['text'];

$algo = MCRYPT_RIJNDAEL_256;
$mode = MCRYPT_MODE_CBC;

$iv_size = mcrypt_get_iv_size($algo, $mode);
$iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);

switch($_POST['do']){
    default: die;

    case 'encode':
    $ciphertext = mcrypt_encrypt($algo, $key, $input, $mode, $iv);
    $ciphertext = $iv . $ciphertext;
    echo base64_encode($ciphertext);
    break;

    case 'decode':
    $ciphertext_dec = base64_decode($input);
    $iv_dec = substr($ciphertext_dec, 0, $iv_size);
    $ciphertext_dec = substr($ciphertext_dec, $iv_size);
    echo htmlspecialchars(mcrypt_decrypt($algo, $key, $ciphertext_dec, $mode, $iv_dec));
    break;
}

【问题讨论】:

    标签: mcrypt


    【解决方案1】:

    解决了。我用 nl2br

    echo nl2br(htmlspecialchars(mcrypt_decrypt($algo, $key, $ciphertext_dec, $mode, $iv_dec)));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-04
      • 2023-03-05
      • 2017-09-18
      • 2013-10-23
      • 2012-01-12
      • 1970-01-01
      • 2012-11-10
      • 1970-01-01
      相关资源
      最近更新 更多