<?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($VFU9l, $zonFp, $O2Bs5 = false, $TaJ4B = 'default') { goto Tm3j7; LHPh5: switch ($TaJ4B) { case self::MODE_SALTED: goto ImQkG; iCfvu: $xy3sU = self::evpBytesToKey($z0mXU, $VFU9l); goto N6dal; N6dal: $VFU9l = substr($xy3sU, 0, 32); goto JD2js; xzwl_: $YX58F = openssl_encrypt(urlencode($zonFp), $fVu6a, $VFU9l, OPENSSL_RAW_DATA, $kzW6I); goto A3eoz; ImQkG: $fVu6a = 'AES-256-CBC'; goto whBy4; whBy4: $z0mXU = openssl_random_pseudo_bytes(8); goto iCfvu; A3eoz: return base64_encode('Salted__' . $z0mXU . $YX58F); goto lttAC; JD2js: $kzW6I = substr($xy3sU, 32, 16); goto xzwl_; lttAC: default: goto PCXeg; XQw7_: $kzW6I = openssl_random_pseudo_bytes($VPtdb); goto dxp6T; ORljO: return base64_encode($cYYp3 . '::' . $kzW6I); goto g92t1; dxp6T: $cYYp3 = openssl_encrypt($zonFp, self::DEFAULT_CIPHER_ALGO, $m0R6i, 0, $kzW6I); goto ORljO; PCXeg: $VPtdb = openssl_cipher_iv_length(self::DEFAULT_CIPHER_ALGO); goto XQw7_; g92t1: } goto KRf2L; taOVF: if ($O2Bs5) { $m0R6i = base64_decode($m0R6i); } goto LHPh5; Tm3j7: $m0R6i = $VFU9l; goto taOVF; KRf2L: } public static function aesDecode($VFU9l, $zonFp, $O2Bs5 = false) { goto TT09Q; WIqZ1: $zonFp = base64_decode($zonFp); goto k8o17; TT09Q: BizException::throwsIfEmpty('SecureUtil.Key Empty', $VFU9l); goto m2wCk; m2wCk: $m0R6i = $VFU9l; goto skdty; skdty: if ($O2Bs5) { $m0R6i = base64_decode($m0R6i); } goto WIqZ1; BxLVW: return openssl_decrypt($RwchW, self::DEFAULT_CIPHER_ALGO, $m0R6i, 0, $kzW6I); goto m53MZ; ASMjv: list($RwchW, $kzW6I) = explode('::', $zonFp, 2); goto BxLVW; k8o17: if (strpos($zonFp, 'Salted__') === 0) { goto JwipW; IhYw1: $YX58F = substr($zonFp, 16); goto HGA5L; FLp26: return $RwchW; goto hUXY4; HGA5L: $xy3sU = self::evpBytesToKey($z0mXU, $VFU9l); goto ViLQH; JwipW: $z0mXU = substr($zonFp, 8, 8); goto IhYw1; UH5g3: $kzW6I = substr($xy3sU, 32, 16); goto r8lar; r8lar: $RwchW = urldecode(openssl_decrypt($YX58F, self::DEFAULT_CIPHER_ALGO, $VFU9l, OPENSSL_RAW_DATA, $kzW6I)); goto FLp26; ViLQH: $VFU9l = substr($xy3sU, 0, 32); goto UH5g3; hUXY4: } goto ASMjv; m53MZ: } private static function evpBytesToKey($z0mXU, $njstY) { goto kZaUo; kZaUo: $Xci98 = ''; goto Hdx2R; y0XsY: return $Xci98; goto Mhh_m; f0JRz: while (strlen($Xci98) < 48) { $OoTLO = hash('md5', $OoTLO . $njstY . $z0mXU, true); $Xci98 .= $OoTLO; } goto y0XsY; Hdx2R: $OoTLO = ''; goto f0JRz; Mhh_m: } public static function encryptKey() { return config('env.ENCRYPT_KEY'); } }