<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Util; use ModStart\Core\Exception\BizException; class SecureUtil { const DEFAULT_CIPHER_ALGO = 'aes-256-cbc'; const MODE_DEFAULT = 'default'; const MODE_SALTED = 'salted'; public static function aesEncode($GUcFO, $IaeCl, $s7Ad7 = false, $oWpPb = 'default') { goto oFOE0; oFOE0: $GQchu = $GUcFO; goto RCJc6; CDBgo: switch ($oWpPb) { case self::MODE_SALTED: goto o0bwd; ay1jH: return base64_encode('Salted__' . $fkNyc . $BivHt); goto DtBnj; o0bwd: $eNE35 = 'AES-256-CBC'; goto C64bY; RRPfX: $BivHt = openssl_encrypt(urlencode($IaeCl), $eNE35, $GUcFO, OPENSSL_RAW_DATA, $gKqrZ); goto ay1jH; C64bY: $fkNyc = openssl_random_pseudo_bytes(8); goto dExMJ; acAES: $gKqrZ = substr($SRj70, 32, 16); goto RRPfX; dExMJ: $SRj70 = self::evpBytesToKey($fkNyc, $GUcFO); goto FQ0Yp; FQ0Yp: $GUcFO = substr($SRj70, 0, 32); goto acAES; DtBnj: default: goto qtNxj; AJNq9: $gKqrZ = openssl_random_pseudo_bytes($QjIMJ); goto heyVz; heyVz: $Gb8pe = openssl_encrypt($IaeCl, self::DEFAULT_CIPHER_ALGO, $GQchu, 0, $gKqrZ); goto ck4BW; qtNxj: $QjIMJ = openssl_cipher_iv_length(self::DEFAULT_CIPHER_ALGO); goto AJNq9; ck4BW: return base64_encode($Gb8pe . '::' . $gKqrZ); goto dkxP9; dkxP9: } goto APU02; RCJc6: if ($s7Ad7) { $GQchu = base64_decode($GQchu); } goto CDBgo; APU02: } public static function aesDecode($GUcFO, $IaeCl, $s7Ad7 = false) { goto RAT7f; RAT7f: BizException::throwsIfEmpty('SecureUtil.Key Empty', $GUcFO); goto X3UAF; LCeJk: list($nS6DP, $gKqrZ) = explode('::', $IaeCl, 2); goto Tjfm0; Tjfm0: return openssl_decrypt($nS6DP, self::DEFAULT_CIPHER_ALGO, $GQchu, 0, $gKqrZ); goto zHhVu; X3UAF: $GQchu = $GUcFO; goto zJOwj; zJOwj: if ($s7Ad7) { $GQchu = base64_decode($GQchu); } goto y2Gd5; iVFxZ: if (strpos($IaeCl, 'Salted__') === 0) { goto Z7wAM; aljEu: return $nS6DP; goto t2JIo; Z7wAM: $fkNyc = substr($IaeCl, 8, 8); goto qouKA; kNu4j: $GUcFO = substr($SRj70, 0, 32); goto DqoEH; vZE1X: $SRj70 = self::evpBytesToKey($fkNyc, $GUcFO); goto kNu4j; DqoEH: $gKqrZ = substr($SRj70, 32, 16); goto Ib87P; qouKA: $BivHt = substr($IaeCl, 16); goto vZE1X; Ib87P: $nS6DP = urldecode(openssl_decrypt($BivHt, self::DEFAULT_CIPHER_ALGO, $GUcFO, OPENSSL_RAW_DATA, $gKqrZ)); goto aljEu; t2JIo: } goto LCeJk; y2Gd5: $IaeCl = base64_decode($IaeCl); goto iVFxZ; zHhVu: } private static function evpBytesToKey($fkNyc, $cv0ME) { goto ddxls; su9xi: $TTasI = ''; goto Y3wWf; Y3wWf: while (strlen($J3fDg) < 48) { $TTasI = hash('md5', $TTasI . $cv0ME . $fkNyc, true); $J3fDg .= $TTasI; } goto ew1Ul; ew1Ul: return $J3fDg; goto C2rSx; ddxls: $J3fDg = ''; goto su9xi; C2rSx: } public static function encryptKey() { return config('env.ENCRYPT_KEY'); } }