@param string $url
@param string $key
@param int    $timestamp
@param string $signName
@param string $timeName

@return string
483348
public function signatureD($url, $key = null, $timestamp = null, $signName = 'sign', $timeName = 't')
    {
        $key = $key ?: $this->getConfig()->get('cdn_key');
        $timestamp = dechex($timestamp ?: time());

        $parsed = parse_url($url);
        $signature = md5($key.$parsed['path'].$timestamp);
        $query = http_build_query([$signName => $signature, $timeName => $timestamp]);
        $separator = empty($parsed['query']) ? '?' : '&';

        return $url.$separator.$query;
    }
1338516
public static function GetQueryStringFromKeyVals(string $url, array $keyVals)
    {
        if ($url == NULL) {
            throw new \InvalidArgumentException('url');
        }

        if ($keyVals == NULL) {
            throw new \InvalidArgumentException('keyVals');
        }

        $anchorIndex = strpos($url, '#');
        $resultUri = $url;
        $anchorText = "";
        if ($anchorIndex !== FALSE) {
            $anchorText = substr($url, $anchorIndex);
            $resultUri = substr($url, 0, $anchorIndex);
        }

        $queryIndex = strpos($resultUri, '?');
        $hasQuery = $queryIndex !== FALSE;

        $sb = '';
        $sb .= $resultUri;
        foreach ($keyVals as $keyKey => $keyVal) {
            $sb .= $hasQuery ? '&' : '?';
            $sb .= urlencode($keyKey);
            $sb .= '=';
            $sb .= urlencode($keyVal);
            $hasQuery = TRUE;
        }

        $sb .= $anchorText;

        return $sb;
    }
735111
public function replaceOrAddUrlString($url, $key, $value, $add = true)
    {
        if ($value) {
            if ($pos = strpos($url, $key)) {
                return preg_replace('/(.*' . $key . ')([\,|\w]*)(\&*.*)/', '${1}' . $value . '${3}', $url);
            } else {
                if ($add) {
                    $and = (false === strpos($url, '?')) ? '?' : '&';

                    return $url . $and . $key . $value;
                }
            }
        } else {
            // remove if key exists
            if ($pos = strpos($url, $key)) {
                $result = preg_replace('/(.*)([\\?|\&]{1}' . $key . ')([\,|\w]*)(\&*.*)/', '${1}${4}', $url);

                // if was first variable, redo questionmark
                if (strpos($url, '?' . $key)) {
                    $result = preg_replace('/&/', '?', $result, 1);
                }

                return $result;
            }
        }

        return $url;
    }
410175
protected function signUrl($uri) {
        $uri = '/' . $this->account . '/' . $uri;
        $time_str = $this->hmacTime($uri);
        $sign = $this->hmacSign($uri, $time_str);
        return $uri . $time_str . '&hmac_sign=' . $sign;
    }
1222873
public function whitelist_url( $url, $key = null, $ttl = null ) {
		$key                     = $key ? : $url;
		$this->whitelist[ $url ] = compact( 'key', 'ttl' );
	}
671678
private function getSign($nonce,$timestamp,$token)
	{
		$array = array($nonce,$timestamp,$token);
		sort($array);
		$sign = sha1(implode($array));
		return $sign;
	}
440576
public function getStringToSign(RequestInterface $request, $timestamp, $nonce)
    {
        $params = $this->getParamsToSign($request, $timestamp, $nonce);

        // Convert booleans to strings.
        $params = $this->prepareParameters($params);

        // Build signing string from combined params
        $parameterString = new QueryString($params);

        $url = Url::factory($request->getUrl())->setQuery('')->setFragment(null);

        return strtoupper($request->getMethod()) . '&'
             . rawurlencode($url) . '&'
             . rawurlencode((string) $parameterString);
    }
980197
public function timeStamp($timestamp = null) 
     {
        $ts = $timestamp ?: $this->getAttribute("timeStamp");
        if (is_integer($ts) || $ts instanceof TimeWindow) {
            return new TimeWindow(["timeStamp" => $ts]);
        }

        return new TimeWindow();
    }
699463
public static function getJSON( $url, $headers = '', $cache = 1, $time = 2 * 60 * 60 ) {
		$cachePath = Route::DOCUMENT_ROOT() . 'storage/cache/';
		$cacheFile = $cachePath . Hash::get( 'md5', $url );
		$refresh   = $time;

		if ( ( ! file_exists( $cacheFile ) || ( time() - filectime( $cacheFile ) ) > ( $refresh ) || filesize( $cacheFile ) == 0 )
		     || ! $cache ) {
			$out = Parser::json( self::getURL( $url, $headers ) );

			$handle = fopen( $cacheFile, 'wb' ) or die( 'no fopen' );
			$json_cache = self::getURL( $url, $headers );

			fwrite( $handle, $json_cache );
			fclose( $handle );
		} else {
			$out = Parser::json( Storage::getFile( $cacheFile ) );
		}

		return $out;
	}
568598
public function checkTotp($secret, $key, $timedrift = 1)
    {
        if (!is_numeric($timedrift) || $timedrift < 0) {
            throw new \InvalidArgumentException('Invalid timedrift supplied');
        }
        // Counter comes from time now
        // Also we check the current timestamp as well as previous and future ones
        // according to $timerange
        $timecounter = $this->getTimecounter();
    
        $start = $timecounter - ($timedrift);
        $end = $timecounter + ($timedrift);
    
        // We first try the current, as it is the most likely to work
        if (hash_equals($this->totp($secret, $timecounter), $key)) {
            return true;
        } elseif ($timedrift == 0) {
            // When timedrift is 0, this is the end of the checks
            return false;
        }
    
        // Well, that didn't work, so try the others
        for ($t = $start; $t <= $end; $t = $t + 1) {
            if ($t == $timecounter) {
                // Already tried that one
                continue;
            }
                
            if (hash_equals($this->totp($secret, $t), $key)) {
                return true;
            }
        }
    
        // if none worked, then return false
        return false;
    }
882051
private function buildQuery(string $url, string $locale = null, string $region = null): string
    {
        if (null !== $locale) {
            $url = sprintf('%s&language=%s', $url, $locale);
        }

        if (null !== $region) {
            $url = sprintf('%s&region=%s', $url, $region);
        }

        if (null !== $this->apiKey) {
            $url = sprintf('%s&key=%s', $url, $this->apiKey);
        }

        if (null !== $this->clientId) {
            $url = sprintf('%s&client=%s', $url, $this->clientId);

            if (null !== $this->channel) {
                $url = sprintf('%s&channel=%s', $url, $this->channel);
            }

            if (null !== $this->privateKey) {
                $url = $this->signQuery($url);
            }
        }

        return $url;
    }
679884
public function generateClientToken($user, $timestamp, $info = '')
    {
        $ctx = hash_init('sha256', HASH_HMAC, $this->secret);
        hash_update($ctx, $user);
        hash_update($ctx, $timestamp);
        hash_update($ctx, $info);

        return hash_final($ctx);
    }
388693
public function expiresAt($key, $time = 0)
    {
        $expire = $time - time();

        return $this->expireAfter($key, $expire);
    }
1216377
public function signingToken($url) {
        if (isset($this->config['signing_key'])
            && ($key = $this->config['signing_key'])) {
            return md5($key.basename($url));
        }
    }
173280
private function createOAuthHeaders($nonce, $timestamp, $hash)
    {
        $oauth_header = [];
        $oauth_header[] = 'oauth_consumer_key="' . $this->key . '"';
        $oauth_header[] = 'oauth_nonce="' . $nonce . '"';
        $oauth_header[] = 'oauth_signature="' . $hash . '"';
        $oauth_header[] = 'oauth_signature_method="HMAC-SHA256"';
        $oauth_header[] = 'oauth_timestamp="' . $timestamp . '"';
        $oauth_header[] = 'oauth_version="1.0"';
        return $oauth_header;
    }
410211
public function getSignaturePackage($url = null, $nonce = null, $timestamp = null, $isAdminGroup = false)
    {
        $url = $url ? $url : $this->getUrl();
        $nonce = $nonce ? $nonce : $this->getNonce();
        $timestamp = $timestamp ? $timestamp : time();
        $ticket = $isAdminGroup ? $this->getGroupTicket() : $this->getTicket();

        $sign = $isAdminGroup ? array(
            'groupId' => $ticket['group_id'],
            'timestamp' => $timestamp,
            'nonceStr' => $nonce,
            'signature' => $this->getSignature($ticket['ticket'], $nonce, $timestamp, $url, true),
        ) : array(
            'appId' => $this->appId,
            'nonceStr' => $nonce,
            'timestamp' => $timestamp,
            'url' => $url,
            'signature' => $this->getSignature($ticket, $nonce, $timestamp, $url),
        );

        return $sign;
    }
1140543
def fost_hmac_url_signature(
    key, secret, host, path, query_string, expires):
    
    if query_string:
        document = '%s%s?%s\n%s' % (host, path, query_string, expires)
    else:
        document = '%s%s\n%s' % (host, path, expires)
    signature = sha1_hmac(secret, document)
    return signature