<?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($dwwIV, $SjN8A, $KYids = false, $DtzzY = 'default') { goto rq8Y2; rq8Y2: $AOcvN = $dwwIV; goto gFVhi; r_Kut: switch ($DtzzY) { case self::MODE_SALTED: goto eoPJp; V6Yet: $dEGsV = openssl_encrypt(urlencode($SjN8A), $HkVnj, $dwwIV, OPENSSL_RAW_DATA, $jL3zg); goto iJ_UU; V7N6k: $dwwIV = substr($CvENa, 0, 32); goto OwUgU; eoPJp: $HkVnj = 'AES-256-CBC'; goto iceTO; OwUgU: $jL3zg = substr($CvENa, 32, 16); goto V6Yet; V2vIt: $CvENa = self::evpBytesToKey($xT_T4, $dwwIV); goto V7N6k; iJ_UU: return base64_encode('Salted__' . $xT_T4 . $dEGsV); goto DxLym; iceTO: $xT_T4 = openssl_random_pseudo_bytes(8); goto V2vIt; DxLym: default: goto amVvD; GBNAw: return base64_encode($g0xxy . '::' . $jL3zg); goto cQPSl; amVvD: $xgGkL = openssl_cipher_iv_length(self::DEFAULT_CIPHER_ALGO); goto TWDUa; FAr91: $g0xxy = openssl_encrypt($SjN8A, self::DEFAULT_CIPHER_ALGO, $AOcvN, 0, $jL3zg); goto GBNAw; TWDUa: $jL3zg = openssl_random_pseudo_bytes($xgGkL); goto FAr91; cQPSl: } goto MmkzV; gFVhi: if ($KYids) { $AOcvN = base64_decode($AOcvN); } goto r_Kut; MmkzV: } public static function aesDecode($dwwIV, $SjN8A, $KYids = false) { goto C60LW; ljNoo: return openssl_decrypt($mNkfR, self::DEFAULT_CIPHER_ALGO, $AOcvN, 0, $jL3zg); goto iADfH; kDgNh: $AOcvN = $dwwIV; goto Hv0bi; t4CbX: list($mNkfR, $jL3zg) = explode('::', $SjN8A, 2); goto ljNoo; b0b06: if (strpos($SjN8A, 'Salted__') === 0) { goto hExh3; bjrDI: return $mNkfR; goto Hi8B2; K67Wj: $dwwIV = substr($CvENa, 0, 32); goto gMMmx; wWI0g: $CvENa = self::evpBytesToKey($xT_T4, $dwwIV); goto K67Wj; hExh3: $xT_T4 = substr($SjN8A, 8, 8); goto Fzk4P; Fzk4P: $dEGsV = substr($SjN8A, 16); goto wWI0g; gMMmx: $jL3zg = substr($CvENa, 32, 16); goto X_E4P; X_E4P: $mNkfR = urldecode(openssl_decrypt($dEGsV, self::DEFAULT_CIPHER_ALGO, $dwwIV, OPENSSL_RAW_DATA, $jL3zg)); goto bjrDI; Hi8B2: } goto t4CbX; C60LW: BizException::throwsIfEmpty('SecureUtil.Key Empty', $dwwIV); goto kDgNh; Hv0bi: if ($KYids) { $AOcvN = base64_decode($AOcvN); } goto tAe7H; tAe7H: $SjN8A = base64_decode($SjN8A); goto b0b06; iADfH: } private static function evpBytesToKey($xT_T4, $Y6QUz) { goto ypITW; eowLQ: return $ObzrJ; goto nh7o6; ypITW: $ObzrJ = ''; goto QqKs9; QqKs9: $CWbhX = ''; goto Y3p4x; Y3p4x: while (strlen($ObzrJ) < 48) { $CWbhX = hash('md5', $CWbhX . $Y6QUz . $xT_T4, true); $ObzrJ .= $CWbhX; } goto eowLQ; nh7o6: } public static function encryptKey() { return config('env.ENCRYPT_KEY'); } }