Prpcrypt工具类
<?php /** * Created by PhpStorm. * User: Auser * Time: 10:55 */ namespace App\Http\Base\Wx; class Prpcrypt { public $key; public function __construct($key) { $this->key = $key; } /** * 对密文进行解密 * @param string $aesCipher 需要解密的密文 * @param string $aesIV 解密的初始向量 * @return string 解密得到的明文 */ public function decrypt($aesCipher, $aesIV) { try { $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); mcrypt_generic_init($module, $this->key, $aesIV); //解密 $decrypted = mdecrypt_generic($module, $aesCipher); mcrypt_generic_deinit($module); mcrypt_module_close($module); } catch (Exception $e) { return array(ErrorCode::$IllegalBuffer, null); } try { $result = PKCS7Encoder2::decode($decrypted); } catch (Exception $e) { //print $e; return array(ErrorCode::$IllegalBuffer, null); } return array(0, $result); } }
ErrorCode状态代码类
<?php /** * Created by PhpStorm. * User: Auser * Time: 10:33 */ namespace App\Http\Base\Wx; class ErrorCode { public static $OK = 0; public static $IllegalAesKey = -41001; public static $IllegalIv = -41002; public static $IllegalBuffer = -41003; public static $DecodeBase64Error = -41004; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持黑区网络。