生成签名 - 用作 转发到第三方

@param string $token
@param string $time
@param string $nonce

@return bool|string
165154
public function makeSignature($token = null, $time = null, $nonce = null)
    {
        if (!is_string($token) || empty($token)) {
            exit("$token 参数错误");
        }

        $timestamp = !empty($time) ? $time : $_GET['timestamp'];
        $nonce     = !empty($nonce) ? $nonce : $_GET['nonce'];
        $tmpArr    = [$token, $timestamp, $nonce];
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);

        return $tmpStr;
    }
1292317
function useNonce($server_url, $timestamp, $salt)
    {
        global $Auth_OpenID_SKEW;

        if (!$this->active) {
            trigger_error("FileStore no longer active", E_USER_ERROR);
            return null;
        }

        if ( abs($timestamp - time()) > $Auth_OpenID_SKEW ) {
            return false;
        }

        if ($server_url) {
            list($proto, $rest) = explode('://', $server_url, 2);
        } else {
            $proto = '';
            $rest = '';
        }

        $parts = explode('/', $rest, 2);
        $domain = $this->_filenameEscape($parts[0]);
        $url_hash = $this->_safe64($server_url);
        $salt_hash = $this->_safe64($salt);

        $filename = sprintf('%08x-%s-%s-%s-%s', $timestamp, $proto,
                            $domain, $url_hash, $salt_hash);
        $filename = $this->nonce_dir . DIRECTORY_SEPARATOR . $filename;

        $result = @fopen($filename, 'x');

        if ($result === false) {
            return false;
        } else {
            fclose($result);
            return true;
        }
    }
233288
@Override
    public String extractSignedToken(String token) {
        String[] chunks = token.split("-", 3);
        if (chunks.length != 3) {
            // Invalid format
            return null;
        }
        String signature = chunks[0];
        String nonce = chunks[1];
        String raw = chunks[2];
        if (constantTimeEquals(signature, sign(nonce + "-" + raw))) {
            return raw;
        } else {
            return null;
        }
    }
315960
public static function get(string $token, string $openID = null, bool $echostr = false, bool $returnArray = false)
    {
        $nonce = 'test';
        $timestamp = time();

        $array = [$nonce, $timestamp, $token];
        sort($array, SORT_STRING);
        $signature = sha1(implode('', $array));
        $data = [
            'signature' => $signature,
            'timestamp' => $timestamp,
            'nonce' => $nonce,
            'openid' => $openID,
            'echostr' => $echostr ? 'echostr' : null,
        ];

        if ($returnArray) {
            return $data;
        }

        return '?'.http_build_query($data);
    }
557563
public function createSignature($nonceStr, $time, $url) {
        $str = "jsapi_ticket=%s&noncestr=%s&timestamp=%d&url=%s";
        $result = sprintf($str, $this->getJsApiTicket()->getTicket(), $nonceStr, $time, $url);
        return sha1($result);
    }
373920
public function decryptXml($xml, $messageSignature, $timestamp , $nonce)
    {
        $errorCode = $this->getMessageCrypt()->decryptMsg($messageSignature, $timestamp, $nonce, $xml, $xml);
        if ($errorCode) {
            $this->lastError = [
                'errcode' => $errorCode,
                'errmsg' => 'XML数据解密失败!'
            ];
            return false;
        }
        return $xml;
    }
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);
    }
1300814
public function signature($url = null, $nonce = null, $timestamp = null)
    {
        $url = $url ? $url : $this->getUrl();
        $nonce = $nonce ? $nonce : Str::quickRandom(10);
        $timestamp = $timestamp ? $timestamp : time();
        $ticket = $this->ticket();

        $sign = [
            'appId'     => $this->getAccessToken()->getCorpId(),
            'nonceStr'  => $nonce,
            'timestamp' => $timestamp,
            'url'       => $url,
            'signature' => $this->getSignature($ticket, $nonce, $timestamp, $url),
        ];

        return $sign;
    }
3892
public function decryptMsg($msgSignature, $nonce, $timestamp, $postXML)
    {
        try {
            $array = XML::parse($postXML);
        } catch (BaseException $e) {
            throw new EncryptionException('Invalid xml.', EncryptionException::ERROR_PARSE_XML);
        }

        $encrypted = $array['Encrypt'];

        $signature = $this->getSHA1($this->token, $timestamp, $nonce, $encrypted);

        if ($signature !== $msgSignature) {
            throw new EncryptionException('Invalid Signature.', EncryptionException::ERROR_INVALID_SIGNATURE);
        }

        return XML::parse($this->decrypt($encrypted, $this->id));
    }
1233940
static function getSignature($token, $timestamp, $nonce)
    {
        //排序
        try {
            $array = array($token, $timestamp, $nonce);
            sort($array, SORT_STRING);
            $str = implode($array);
            return sha1($str);
        } catch (\Exception $e) {
            @error_log('getSignature Error: ' . $e->getMessage(), 0);
            return FALSE;
        }
    }
1122525
static function get_jsapi_signature($jsapi_ticket, $nonceStr, $timestamp, $url)
    {
        //排序
        try {
            $str = "jsapi_ticket=$jsapi_ticket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
            return sha1($str);
        } catch (\Exception $e) {
            @error_log('get_jsapi_signature Error: ' . $e->getMessage(), 0);
            return FALSE;
        }
    }
379313
public function getSignature($ticket, $nonce, $timestamp, $url, $isAdminGroup = false)
    {
        return $isAdminGroup ? sha1("group_ticket={$ticket}&noncestr={$nonce}&timestamp={$timestamp}&url={$url}") : sha1("jsapi_ticket={$ticket}&noncestr={$nonce}&timestamp={$timestamp}&url={$url}");
    }
715988
private function createNonce()
    {
        if (function_exists('wp_create_nonce')) {
            return wp_create_nonce($this->nonceKey);
        }

        $nonce = md5(microtime(true).$this->nonceKey);
        if (empty($_SESSION['csrf_tokens'])) {
            $_SESSION['csrf_tokens'] = array();
        }
        $_SESSION['csrf_tokens'][$nonce] = true;

        return $nonce;
    }
231231
function useNonce($server_url, $timestamp, $salt)
    {
        global $Auth_OpenID_SKEW;

        // save one request to memcache when nonce obviously expired
        if (abs($timestamp - time()) > $Auth_OpenID_SKEW) {
            return false;
        }

        // returns false when nonce already exists
        // otherwise adds nonce
        return $this->connection->add(
            'openid_nonce_' . sha1($server_url) . '_' . sha1($salt),
            1, // any value here
            $this->compress,
            $Auth_OpenID_SKEW);
    }
750983
public static function verifyNonce($nonce, $action)
    {
        //Safety check for multiple nonces
        if (is_array($nonce)) {
            $nonce = array_shift($nonce);
        }

        //Nonce generated 0-12 hours ago
        if ($nonce === self::getNonce($action)) {
            return true;
        }

        //Nonce generated 12-24 hours ago
        $previousTick = true;

        return $nonce === self::getNonce($action, $previousTick);
    }
420096
private function createDataElement(RequestInterface $request, $nonce, $timestamp)
    {
        $data = [];
        if ($request->getMethod() === 'POST') {
            $data[] = rawurlencode($request->getBody()->getContents());
        }
        $data[] = rawurlencode('oauth_consumer_key=' . $this->key);
        $data[] = rawurlencode('oauth_nonce=' . $nonce);
        $data[] = rawurlencode('oauth_signature_method=HMAC-SHA256');
        $data[] = rawurlencode('oauth_timestamp=' . $timestamp);
        $data[] = rawurlencode('oauth_version=1.0');

        return $data;
    }
860562
private static String generateSignature(AuthToken token) {
        StringBuilder builder = new StringBuilder();
        builder.append(token.getPrincipal());
        builder.append("||"); //$NON-NLS-1$
        builder.append(token.getExpiresOn().getTime());
        builder.append("||"); //$NON-NLS-1$
        builder.append(token.getIssuedOn().getTime());
        builder.append("||"); //$NON-NLS-1$
        TreeSet<String> roles = new TreeSet<>(token.getRoles());
        boolean first = true;
        for (String role : roles) {
            if (first) {
                first = false;
            } else {
                builder.append(","); //$NON-NLS-1$
            }
            builder.append(role);
        }
        builder.append("||"); //$NON-NLS-1$
        builder.append(sharedSecretSource.getSharedSecret());
        return DigestUtils.sha256Hex(builder.toString());
    }