PHP中使用了mcrypt_decrypt函数处理Json Json_decode 返回空值或者 NULL 的问题 json_last_error 3

昨天弄了一天

function Daes($text){
	$iv='1234567812345678';
	$decode = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, md5($iv), base64_decode($text), MCRYPT_MODE_CBC, $iv);
	return $decode;
}

按理说都是正常的。但是怎么整 echo json_last_error的时候都返回3 

还以为是编码问题,搞了一晚上查手册

Description
string mcrypt_decrypt ( string cipher, string key, string data, string mode [, string iv] )


mcrypt_decrypt() decrypts the data and returns the unencrypted data. 

Cipher is one of the MCRYPT_ciphername constants of the name of the algorithm as string. 

Key is the key with which the data is encrypted. If it's smaller that the required keysize, it is padded with '\0'. 

Data is the data that will be decrypted with the given cipher and mode. If the size of the data is not n * blocksize, the data will be padded with '\0'. 

Mode is one of the MCRYPT_MODE_modename constants of one of "ecb", "cbc", "cfb", "ofb", "nofb" or "stream". 

The IV parameter is used for the initialisation in CBC, CFB, OFB modes, and in some algorithms in STREAM mode. If you do not supply an IV, while it is needed for an algorithm, the function issues a warning and uses an IV with all bytes set to '\0'. 

操蛋,用'\0'填充了。

加 一行str_replace("\0","",$re);

就正常 了。日个粑粑的

  

posted @ 2016-06-16 09:18  钱佬  阅读(457)  评论(0编辑  收藏  举报