<?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($HQKqq, $Sj05q, $posUg = false, $lZlEV = 'default') { goto Y3QGz; D_X5y: switch ($lZlEV) { case self::MODE_SALTED: goto ALIPL; IKuGj: $B22Vy = openssl_encrypt(urlencode($Sj05q), $hiFdg, $HQKqq, OPENSSL_RAW_DATA, $qYlv7); goto J9fKt; KwMRR: $BY4Ah = self::evpBytesToKey($RG4Vr, $HQKqq); goto wsXNp; E4tsq: $RG4Vr = openssl_random_pseudo_bytes(8); goto KwMRR; fBDKW: $qYlv7 = substr($BY4Ah, 32, 16); goto IKuGj; J9fKt: return base64_encode('Salted__' . $RG4Vr . $B22Vy); goto jgYM6; ALIPL: $hiFdg = 'AES-256-CBC'; goto E4tsq; wsXNp: $HQKqq = substr($BY4Ah, 0, 32); goto fBDKW; jgYM6: default: goto P3y_I; s4DVs: $qYlv7 = openssl_random_pseudo_bytes($npCWe); goto cuovn; P3y_I: $npCWe = openssl_cipher_iv_length(self::DEFAULT_CIPHER_ALGO); goto s4DVs; cuovn: $sgVmb = openssl_encrypt($Sj05q, self::DEFAULT_CIPHER_ALGO, $TZvSt, 0, $qYlv7); goto LQUTe; LQUTe: return base64_encode($sgVmb . '::' . $qYlv7); goto Bw9cv; Bw9cv: } goto XIE05; Y3QGz: $TZvSt = $HQKqq; goto Z9fJI; Z9fJI: if ($posUg) { $TZvSt = base64_decode($TZvSt); } goto D_X5y; XIE05: } public static function aesDecode($HQKqq, $Sj05q, $posUg = false) { goto ELq8V; eIND7: if (strpos($Sj05q, 'Salted__') === 0) { goto efVF0; l5Fnh: $qYlv7 = substr($BY4Ah, 32, 16); goto AzC1S; UJOVX: $BY4Ah = self::evpBytesToKey($RG4Vr, $HQKqq); goto va7Vc; AzC1S: $vovFx = urldecode(openssl_decrypt($B22Vy, self::DEFAULT_CIPHER_ALGO, $HQKqq, OPENSSL_RAW_DATA, $qYlv7)); goto TENHS; Ba2xu: $B22Vy = substr($Sj05q, 16); goto UJOVX; efVF0: $RG4Vr = substr($Sj05q, 8, 8); goto Ba2xu; va7Vc: $HQKqq = substr($BY4Ah, 0, 32); goto l5Fnh; TENHS: return $vovFx; goto iD2Q3; iD2Q3: } goto FDR3g; FDR3g: list($vovFx, $qYlv7) = explode('::', $Sj05q, 2); goto KHVSg; KHVSg: return openssl_decrypt($vovFx, self::DEFAULT_CIPHER_ALGO, $TZvSt, 0, $qYlv7); goto MV5Xv; j9ZL4: if ($posUg) { $TZvSt = base64_decode($TZvSt); } goto CTV6j; ELq8V: $TZvSt = $HQKqq; goto j9ZL4; CTV6j: $Sj05q = base64_decode($Sj05q); goto eIND7; MV5Xv: } private static function evpBytesToKey($RG4Vr, $f8snf) { goto lm3MG; HY431: return $hmrlC; goto pWTtX; sF7DR: while (strlen($hmrlC) < 48) { $CDwyp = hash('md5', $CDwyp . $f8snf . $RG4Vr, true); $hmrlC .= $CDwyp; } goto HY431; ivEXQ: $CDwyp = ''; goto sF7DR; lm3MG: $hmrlC = ''; goto ivEXQ; pWTtX: } public static function encryptKey() { return modstart_config('EncryptKey', 'mock-encrypt-key-random-string--'); } }