正在显示
1 个修改的文件
包含
67 行增加
和
21 行删除
| @@ -29,37 +29,64 @@ class WXBizDataCrypt | @@ -29,37 +29,64 @@ class WXBizDataCrypt | ||
| 29 | * | 29 | * |
| 30 | * @return int 成功0,失败返回对应的错误码 | 30 | * @return int 成功0,失败返回对应的错误码 |
| 31 | */ | 31 | */ |
| 32 | - public function decryptData($encryptedData, $iv, &$data) | 32 | + public function decryptData( $encryptedData, $iv, &$data ) |
| 33 | + | ||
| 33 | { | 34 | { |
| 35 | + | ||
| 34 | if (strlen($this->sessionKey) != 24) { | 36 | if (strlen($this->sessionKey) != 24) { |
| 37 | + | ||
| 35 | return ErrorCode::$IllegalAesKey; | 38 | return ErrorCode::$IllegalAesKey; |
| 39 | + | ||
| 36 | } | 40 | } |
| 37 | - $aesKey = base64_decode($this->sessionKey); | ||
| 38 | 41 | ||
| 42 | + $aesKey=base64_decode($this->sessionKey); | ||
| 39 | 43 | ||
| 40 | if (strlen($iv) != 24) { | 44 | if (strlen($iv) != 24) { |
| 45 | + | ||
| 41 | return ErrorCode::$IllegalIv; | 46 | return ErrorCode::$IllegalIv; |
| 47 | + | ||
| 42 | } | 48 | } |
| 43 | - $aesIV = base64_decode($iv); | ||
| 44 | 49 | ||
| 45 | - $aesCipher = base64_decode($encryptedData); | 50 | + $aesIV=base64_decode($iv); |
| 51 | + | ||
| 52 | +// $aesCipher=base64_decode($encryptedData); | ||
| 53 | + | ||
| 54 | + $aesCipher=$encryptedData; | ||
| 46 | 55 | ||
| 47 | $pc = new Prpcrypt($aesKey); | 56 | $pc = new Prpcrypt($aesKey); |
| 48 | - $result = $pc->decrypt($aesCipher, $aesIV); | 57 | + |
| 58 | + $result = $pc->decrypt($aesCipher,$aesIV); | ||
| 59 | + | ||
| 60 | + var_dump($result); | ||
| 49 | 61 | ||
| 50 | if ($result[0] != 0) { | 62 | if ($result[0] != 0) { |
| 63 | + | ||
| 51 | return $result[0]; | 64 | return $result[0]; |
| 65 | + | ||
| 52 | } | 66 | } |
| 53 | 67 | ||
| 54 | - $dataObj = json_decode($result[1]); | ||
| 55 | - if ($dataObj == NULL) { | ||
| 56 | - return ErrorCode::$IllegalBuffer; | 68 | + $dataObj=json_decode( $result[1] ); |
| 69 | + | ||
| 70 | + if( $dataObj == NULL ) | ||
| 71 | + | ||
| 72 | + { | ||
| 73 | + | ||
| 74 | + return ErrorCode::$IllegalBuffer.'--'; | ||
| 75 | + | ||
| 57 | } | 76 | } |
| 58 | - if ($dataObj->watermark->appid != $this->appid) { | ||
| 59 | - return ErrorCode::$IllegalBuffer; | 77 | + |
| 78 | + if( $dataObj->watermark->appid != $this->appid ) | ||
| 79 | + | ||
| 80 | + { | ||
| 81 | + | ||
| 82 | + return ErrorCode::$IllegalBuffer.';;'; | ||
| 83 | + | ||
| 60 | } | 84 | } |
| 85 | + | ||
| 61 | $data = $result[1]; | 86 | $data = $result[1]; |
| 87 | + | ||
| 62 | return ErrorCode::$OK; | 88 | return ErrorCode::$OK; |
| 89 | + | ||
| 63 | } | 90 | } |
| 64 | 91 | ||
| 65 | } | 92 | } |
| @@ -133,33 +160,52 @@ class Prpcrypt | @@ -133,33 +160,52 @@ class Prpcrypt | ||
| 133 | * @param string $aesIV 解密的初始向量 | 160 | * @param string $aesIV 解密的初始向量 |
| 134 | * @return string 解密得到的明文 | 161 | * @return string 解密得到的明文 |
| 135 | */ | 162 | */ |
| 136 | - public function decrypt($aesCipher, $aesIV) | ||
| 137 | - { | 163 | + public function decrypt( $aesCipher, $aesIV ) |
| 138 | 164 | ||
| 165 | + { | ||
| 139 | 166 | ||
| 140 | try { | 167 | try { |
| 141 | - $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); | ||
| 142 | - mcrypt_generic_init($module, $this->key, $aesIV); | ||
| 143 | 168 | ||
| 144 | - //解密 | ||
| 145 | - $decrypted = mdecrypt_generic($module, $aesCipher); | ||
| 146 | - mcrypt_generic_deinit($module); | ||
| 147 | - mcrypt_module_close($module); | 169 | +// $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); |
| 170 | + | ||
| 171 | +// mcrypt_generic_init($module, $this->key, $aesIV); | ||
| 172 | + | ||
| 173 | +// //解密 | ||
| 174 | + | ||
| 175 | +// $decrypted = mdecrypt_generic($module, $aesCipher); | ||
| 176 | + | ||
| 177 | +// mcrypt_generic_deinit($module); | ||
| 178 | + | ||
| 179 | +// mcrypt_module_close($module); | ||
| 180 | + | ||
| 181 | + $decrypted = openssl_decrypt($aesCipher,'AES-128-CBC',$this->key,OPENSSL_ZERO_PADDING,$aesIV); | ||
| 182 | + | ||
| 183 | +// var_dump($decrypted); | ||
| 184 | + | ||
| 148 | } catch (Exception $e) { | 185 | } catch (Exception $e) { |
| 186 | + | ||
| 149 | return array(ErrorCode::$IllegalBuffer, null); | 187 | return array(ErrorCode::$IllegalBuffer, null); |
| 150 | - } | ||
| 151 | 188 | ||
| 189 | + } | ||
| 152 | 190 | ||
| 153 | try { | 191 | try { |
| 154 | - //去除补位字符 | 192 | + |
| 193 | +//去除补位字符 | ||
| 194 | + | ||
| 155 | $pkc_encoder = new PKCS7Encoder; | 195 | $pkc_encoder = new PKCS7Encoder; |
| 196 | + | ||
| 156 | $result = $pkc_encoder->decode($decrypted); | 197 | $result = $pkc_encoder->decode($decrypted); |
| 157 | 198 | ||
| 158 | } catch (Exception $e) { | 199 | } catch (Exception $e) { |
| 159 | - //print $e; | 200 | + |
| 201 | +//print $e; | ||
| 202 | + | ||
| 160 | return array(ErrorCode::$IllegalBuffer, null); | 203 | return array(ErrorCode::$IllegalBuffer, null); |
| 204 | + | ||
| 161 | } | 205 | } |
| 206 | + | ||
| 162 | return array(0, $result); | 207 | return array(0, $result); |
| 208 | + | ||
| 163 | } | 209 | } |
| 164 | } | 210 | } |
| 165 | 211 |
-
请 注册 或 登录 后发表评论