<?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($oMJcb, $dTnlu, $ZTpEH = false, $qOE89 = 'default') { goto wQX1C; G2WR3: if ($ZTpEH) { $HrHm7 = base64_decode($HrHm7); } goto JSyTG; JSyTG: switch ($qOE89) { case self::MODE_SALTED: goto CXfRW; Abdyg: $oMJcb = substr($TYgPl, 0, 32); goto hMpyu; hMpyu: $JMLhA = substr($TYgPl, 32, 16); goto qvFS9; UzkSU: $UTbXG = openssl_random_pseudo_bytes(8); goto cyl1s; WnbCP: return base64_encode('Salted__' . $UTbXG . $GqopE); goto dkGyn; cyl1s: $TYgPl = self::evpBytesToKey($UTbXG, $oMJcb); goto Abdyg; CXfRW: $UVOMF = 'AES-256-CBC'; goto UzkSU; qvFS9: $GqopE = openssl_encrypt(urlencode($dTnlu), $UVOMF, $oMJcb, OPENSSL_RAW_DATA, $JMLhA); goto WnbCP; dkGyn: default: goto jdAaK; AzvUq: $JMLhA = openssl_random_pseudo_bytes($Nw0CA); goto wVq99; YcMsb: return base64_encode($zMHB4 . '::' . $JMLhA); goto lqBN5; wVq99: $zMHB4 = openssl_encrypt($dTnlu, self::DEFAULT_CIPHER_ALGO, $HrHm7, 0, $JMLhA); goto YcMsb; jdAaK: $Nw0CA = openssl_cipher_iv_length(self::DEFAULT_CIPHER_ALGO); goto AzvUq; lqBN5: } goto W_ZPx; wQX1C: $HrHm7 = $oMJcb; goto G2WR3; W_ZPx: } public static function aesDecode($oMJcb, $dTnlu, $ZTpEH = false) { goto LCT2H; LCT2H: BizException::throwsIfEmpty('SecureUtil.Key Empty', $oMJcb); goto zBkvk; oDLKE: if (strpos($dTnlu, 'Salted__') === 0) { goto OvpWr; OvpWr: $UTbXG = substr($dTnlu, 8, 8); goto IkIdG; IoWXP: $n2gAk = urldecode(openssl_decrypt($GqopE, self::DEFAULT_CIPHER_ALGO, $oMJcb, OPENSSL_RAW_DATA, $JMLhA)); goto MAvKU; BpgH4: $oMJcb = substr($TYgPl, 0, 32); goto eVuED; Jr2SA: $TYgPl = self::evpBytesToKey($UTbXG, $oMJcb); goto BpgH4; MAvKU: return $n2gAk; goto mRUvB; eVuED: $JMLhA = substr($TYgPl, 32, 16); goto IoWXP; IkIdG: $GqopE = substr($dTnlu, 16); goto Jr2SA; mRUvB: } goto FPnyU; lGY51: if ($ZTpEH) { $HrHm7 = base64_decode($HrHm7); } goto rI0L4; FPnyU: list($n2gAk, $JMLhA) = explode('::', $dTnlu, 2); goto T4oXY; rI0L4: $dTnlu = base64_decode($dTnlu); goto oDLKE; zBkvk: $HrHm7 = $oMJcb; goto lGY51; T4oXY: return openssl_decrypt($n2gAk, self::DEFAULT_CIPHER_ALGO, $HrHm7, 0, $JMLhA); goto h6Zq4; h6Zq4: } private static function evpBytesToKey($UTbXG, $wjfbs) { goto q8RlX; ICLk2: return $CWsSZ; goto RaunQ; q8RlX: $CWsSZ = ''; goto AOzJp; PsgV1: while (strlen($CWsSZ) < 48) { $xJwEN = hash('md5', $xJwEN . $wjfbs . $UTbXG, true); $CWsSZ .= $xJwEN; } goto ICLk2; AOzJp: $xJwEN = ''; goto PsgV1; RaunQ: } public static function encryptKey() { return config('env.ENCRYPT_KEY'); } }