报错内容
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_generic(): 41 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 111
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_generic_deinit(): 41 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 113
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_module_close(): 41 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 115
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_generic(): 42 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 111
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_generic_deinit(): 42 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 113
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_module_close(): 42 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 115
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_generic(): 43 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 111
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_generic_deinit(): 43 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 113
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_module_close(): 43 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 115
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_generic(): 44 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 111
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_generic_deinit(): 44 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 113
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_module_close(): 44 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 115
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_generic(): 45 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 111
[31-Oct-2016 15:09:32 Asia/Shanghai] PHP Warning: mcrypt_generic_deinit(): 45 is not a valid MCrypt resource in E:\php\developer\dev\yungou\system\modules\pay\lib\jdpay\common\TDESUtil.php on line 113
使用源码
// 加密算法
public static function encrypt($input, $key) {
$size = mcrypt_get_block_size ( 'des', 'ecb' );
$td = mcrypt_module_open ( MCRYPT_3DES, '', 'ecb', '' );
$iv = @mcrypt_create_iv ( mcrypt_enc_get_iv_size ( $td ), MCRYPT_RAND );
// 使用MCRYPT_3DES算法,cbc模式
@mcrypt_generic_init ( $td, $key, $iv );
// 初始处理
$data = mcrypt_generic ( $td, $input );
// 加密
mcrypt_generic_deinit ( $td );
// 结束
mcrypt_module_close ( $td );
return $data;
}
public static function decrypt($encrypted, $key) {
//$encrypted = base64_decode($encrypted);
$td = mcrypt_module_open ( MCRYPT_3DES, '', 'ecb', '' ); // 使用MCRYPT_DES算法,cbc模式
$iv = @mcrypt_create_iv ( mcrypt_enc_get_iv_size ( $td ), MCRYPT_RAND );
$ks = mcrypt_enc_get_key_size ( $td );
@mcrypt_generic_init ( $td, $key, $iv ); // 初始处理
$decrypted = mdecrypt_generic ( $td, $encrypted ); // 解密
mcrypt_generic_deinit ( $td ); // 结束
mcrypt_module_close ( $td );
//$y = TDESUtil::pkcs5Unpad ( $decrypted );
return $decrypted;
}