Exemple #1
0
function encryptUrl($url, $maxRandomStrLen = '', $encKeyStr = '', $encIvecStr = '')
{
    $status = -1;
    $logArr['func'] = "encryptUrl";
    /**
     * encryptUrl random string length
     * @var long
     */
    if (empty($maxRandomStrLen) || intval($maxRandomStrLen) < 1) {
        $maxRandomStrLen = CSmarty::getMaxRandomStrLen();
    }
    /**
     * encryptUrl key string, ie: token
     * @var string
     */
    if (empty($encKeyStr)) {
        $encKeyStr = CSmarty::getEncKeyStr();
    }
    if (empty($encIvecStr)) {
        $encIvecStr = CSmarty::getEncIvecStr();
    }
    $randState = CSmarty::getRandState();
    $flag = CSmarty::getFlag();
    $logArr['url'] = $url;
    $logArr['encKeyStr'] = $encKeyStr;
    $logArr['maxRandomStrLen'] = $maxRandomStrLen;
    $logArr['randState'] = $randState;
    $logArr['flag'] = $flag;
    $url = trim($url);
    if (strlen($url) == 0) {
        return false;
    }
    $result = hilight_encryptUrl($url, $encKeyStr, $encIvecStr, $maxRandomStrLen, $randState, $flag);
    $logArr['result'] = $result;
    if ($GLOBALS['ENC_LOG']) {
        CLog::notice("hilight_encryptUrl end", $status, $logArr, 1);
    }
    if (false == $result) {
        CLog::warning("fail to call hilight_encryptUrl", $status, $logArr, 1);
    }
    $maxEncWarningLen = CSmarty::getMaxEncWarningLen();
    $length = strlen($result);
    /**
     * if $length is greater than the max length of url, then return false,ie  fail to encrypt
     * 
     */
    if ($maxEncWarningLen > 0 && $length > $maxEncWarningLen) {
        $logArr['length'] = $length;
        $logArr['maxEncWarningLen'] = $maxEncWarningLen;
        CLog::warning("encryption url len is {$length}, limit {$maxEncWarningLen}", $status, $logArr, 1);
    }
    return $result;
}