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);

就正常 了。日个粑粑的

  

转载于:https://www.cnblogs.com/qianlao/p/5589840.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值