PHP MCRYPT加密/解密返回不可见的奇怪字符? [英] PHP MCRYPT encrypt/decrypt returns invisible strange characters?

查看:253
本文介绍了PHP MCRYPT加密/解密返回不可见的奇怪字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mcrypt_decrypt 是给我额外的不可见的字符,它是不可见的,只是在页面上回显。只能通过将其写入文本文件。方法,只是显示在页面上是好的,很难被注意到。

mcrypt_decrypt is giving me additional invisible characters which are NOT VISIBLE by just echoing out on the page. Can ONLY BE SEEN by writing it to the text file. Means, just displaying on the page is OK and hard to be noticed.

这里是Googling的代码示例。 请指导我正确的用法是有错误

Here is the code sample by Googling. Please guide me what is the correct usage is there's something wrong:

function encrypt ($pure_string, $key) {
    $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $encrypted_string = mcrypt_encrypt(MCRYPT_BLOWFISH, $encryption_key, $pure_string, MCRYPT_MODE_ECB, $iv);
    return $encrypted_string;
}

function decrypt ($encrypted_string, $key) {
    $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $decrypted_string = mcrypt_decrypt(MCRYPT_BLOWFISH, $encryption_key, $encrypted_string, MCRYPT_MODE_ECB, $iv);
    return $decrypted_string;
}

但我尝试时:

$encrypted_string = encrypt("This is the original string.", "ABC123");
echo decrypt($encrypted_string, "ABC123");

..我得到了类似的东西:

.. i am getting something like:

This is the original string.�������

这个奇怪的字符 实际上不可见您/ i只是 echo it。只能通过写入文本文件才能看到。

This strange characters ������� are actually not visible when you/ i just echo it. Can only be seen by writing into the text file.


  • 那么我失踪了什么?

  • 是否有任何完美的方法来实现这种加密/解密?

谢谢。

推荐答案

rtrim()将删除mcrypt添加的填充...

rtrim() will remove the padding that mcrypt added...

这篇关于PHP MCRYPT加密/解密返回不可见的奇怪字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆