<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Util; class SecureUtil { const DEFAULT_CIPHER_ALGO = 'aes-256-cbc'; const MODE_DEFAULT = 'default'; const MODE_SALTED = 'salted'; public static function aesEncode($rvTrU, $OTBPk, $ZXB0R = false, $ybhyk = 'default') { goto c1LmY; c1LmY: $oyAjb = $rvTrU; goto sK2uD; sK2uD: if ($ZXB0R) { $oyAjb = base64_decode($oyAjb); } goto PRjik; PRjik: switch ($ybhyk) { case self::MODE_SALTED: goto C684t; hPx9F: $onY4Q = openssl_random_pseudo_bytes(8); goto IL_QV; C684t: $HxDDI = 'AES-256-CBC'; goto hPx9F; Rrt67: $erTwK = substr($Jm9DM, 32, 16); goto mizwk; e7QkY: $rvTrU = substr($Jm9DM, 0, 32); goto Rrt67; IL_QV: $Jm9DM = self::evpBytesToKey($onY4Q, $rvTrU); goto e7QkY; mizwk: $tcdYx = openssl_encrypt(urlencode($OTBPk), $HxDDI, $rvTrU, OPENSSL_RAW_DATA, $erTwK); goto RP7FP; RP7FP: return base64_encode('Salted__' . $onY4Q . $tcdYx); goto T5Qj8; T5Qj8: default: goto AsZbj; AsZbj: $xCq2X = openssl_cipher_iv_length(self::DEFAULT_CIPHER_ALGO); goto nhsRl; bQZqN: $Mw3Xo = openssl_encrypt($OTBPk, self::DEFAULT_CIPHER_ALGO, $oyAjb, 0, $erTwK); goto SNLMP; nhsRl: $erTwK = openssl_random_pseudo_bytes($xCq2X); goto bQZqN; SNLMP: return base64_encode($Mw3Xo . '::' . $erTwK); goto CuUud; CuUud: } goto iM8zr; iM8zr: } public static function aesDecode($rvTrU, $OTBPk, $ZXB0R = false) { goto ydaHu; wjWuK: if ($ZXB0R) { $oyAjb = base64_decode($oyAjb); } goto SXf7t; mimm0: if (strpos($OTBPk, 'Salted__') === 0) { goto aJGKR; q23QK: $tcdYx = substr($OTBPk, 16); goto jZc_d; viSUQ: $erTwK = substr($Jm9DM, 32, 16); goto GQccV; q53lq: return $jEAjA; goto NRCOS; aJGKR: $onY4Q = substr($OTBPk, 8, 8); goto q23QK; GQccV: $jEAjA = urldecode(openssl_decrypt($tcdYx, self::DEFAULT_CIPHER_ALGO, $rvTrU, OPENSSL_RAW_DATA, $erTwK)); goto q53lq; jZc_d: $Jm9DM = self::evpBytesToKey($onY4Q, $rvTrU); goto sWRn2; sWRn2: $rvTrU = substr($Jm9DM, 0, 32); goto viSUQ; NRCOS: } goto ynbFO; GYM6l: return openssl_decrypt($jEAjA, self::DEFAULT_CIPHER_ALGO, $oyAjb, 0, $erTwK); goto pci6N; ydaHu: $oyAjb = $rvTrU; goto wjWuK; ynbFO: list($jEAjA, $erTwK) = explode('::', $OTBPk, 2); goto GYM6l; SXf7t: $OTBPk = base64_decode($OTBPk); goto mimm0; pci6N: } private static function evpBytesToKey($onY4Q, $SQma7) { goto DCmed; DCmed: $ZLRmP = ''; goto gHVQ0; ki3_G: while (strlen($ZLRmP) < 48) { $WLkcu = hash('md5', $WLkcu . $SQma7 . $onY4Q, true); $ZLRmP .= $WLkcu; } goto PfHG4; PfHG4: return $ZLRmP; goto egcQp; gHVQ0: $WLkcu = ''; goto ki3_G; egcQp: } public static function encryptKey() { return modstart_config('EncryptKey', 'mock-encrypt-key-random-string--'); } }