Generate a authorized token
@param string $secret
@param string $module
@param boolean $isOdd

@return string
763371
public static function generateToken($secret, $module = 'PSFS', $isOdd = null)
    {
        $ts = self::getTs($isOdd);
        $module = strtolower($module);
        $hash = hash_hmac('sha256', $module, $secret);
        $token = self::mixSecret($ts, $hash);
        $finalToken = self::mixToken($ts, $hash, $token);
        return $finalToken;
    }
543347
public function sign(string $data, string $secret): string {
        return base64_encode(hash_hmac('md5', $data, $secret, true));
    }
277788
public function setToken($token, $secret)
    {
        Argument::i()
            //argument 1 must be a string
            ->test(1, 'string')
            //argument 2 must be a string
            ->test(2, 'string');
        
        $this->requestToken = $token;
        $this->requestSecret = $secret;
        
        return $this;
    }
482940
public static function shaHashBase64($signature, $secret)
    {
        return base64_encode(
            hash_hmac(Hmac::ALGORITHM_SHA256, $signature, $secret, true)
        );
    }
1330037
public String generate(String secret) {
    return generate(secret == null ? null : secret.getBytes(StandardCharsets.UTF_8));
  }
124006
private static function _createOauthUrlForOpenid($app_id, $app_secret, $code)
    {
        $urlObj = array();
        $urlObj['appid'] = $app_id;
        $urlObj['secret'] = $app_secret;
        $urlObj['code'] = $code;
        $urlObj['grant_type'] = 'authorization_code';
        $queryStr = http_build_query($urlObj);

        return 'https://api.weixin.qq.com/sns/oauth2/access_token?' . $queryStr;
    }
1184943
protected function generateSig($endpoint, array $params, $secret)
    {
        $sig = $endpoint;
        ksort($params);
        foreach ($params as $key => $val) {
            $sig .= "|$key=$val";
        }
        return hash_hmac('sha256', $sig, $secret, false);
    }
998621
public static function authTokenMiddleware(string $issuer, string $secret): callable
    {
        return Middleware::mapRequest(
            function (RequestInterface $request) use ($issuer, $secret) {
                return new Request(
                    $request->getMethod(),
                    $request->getUri(),
                    \array_merge($request->getHeaders(), ['Authorization' => 'JWT '.JWTGenerator::generate($request, $issuer, $secret)]),
                    $request->getBody()
                );
            }
        );
    }
1356278
function set_secret($secret = null)
    {
        // generate random hash and store in session
        if (!$secret) {
            if (!empty($_SESSION['auth_secret'])) {
                $secret = $_SESSION['auth_secret'];
            }
            else {
                $secret = rcube_utils::random_bytes(strlen($this->key));
            }
        }

        $_SESSION['auth_secret'] = $secret;
    }
231369
public function getQRCodeInlineV1($company, $holder, $secret, $size = 200, $encoding = 'utf-8')
    {
        $url = $this->getQRCodeUrl($company, $holder, $secret);

        $renderer = $this->imageBackEnd;
        $renderer->setWidth($size);
        $renderer->setHeight($size);

        $bacon = new BaconQrCodeWriter($renderer);
        $data = $bacon->writeString($url, $encoding);

        if ($this->imageBackEnd instanceof Png) {
            return 'data:image/png;base64,'.base64_encode($data);
        }
        return $data;
    }
1255228
public static function parser(string $token, string $secret): Parse
    {
        $jwt = new Jwt($token, $secret);

        return new Parse($jwt, new Validate(), new Encode());
    }
829437
private function getResponse(string $secret, string $challenge): string
    {
        if (\strlen($secret) > 64) {
            $secret = pack('H32', md5($secret));
        }

        if (\strlen($secret) < 64) {
            $secret = str_pad($secret, 64, \chr(0));
        }

        $kipad = substr($secret, 0, 64) ^ str_repeat(\chr(0x36), 64);
        $kopad = substr($secret, 0, 64) ^ str_repeat(\chr(0x5C), 64);

        $inner = pack('H32', md5($kipad.$challenge));
        $digest = md5($kopad.$inner);

        return $digest;
    }
1090179
public static function fetchClient($client_id, $client_secret = null)
	{
		$query = DB::table('oauth_clients')->where('id', $client_id);
		if (null !== $client_secret) {
			$query->where('secret', $client_secret);
		}
		$client = $query->first();
		
		if (!$client) {
			return null;
		}
		
		return new Authentication\Client($client_id, (array) $client);
	}
721002
public function setCredentials($appId, $secretKey)
    {
        $this->appId = $appId;
        $this->secretKey = $secretKey;
        return $this;
    }
254322
public static function getHeader(string $token, string $secret): array
    {
        $parser = self::parser($token, $secret);

        return $parser->validate()->parse()->getHeader();
    }
578926
public static function generate(RequestInterface $request, string $issuer, string $secret): string
    {
        $data = [
            'iss' => $issuer,
            'iat' => \time(),
            'exp' => \strtotime('+1 day'),
            'qsh' => QSHGenerator::generate((string) $request->getUri(), $request->getMethod()),
        ];

        return JWT::encode($data, $secret);
    }
490526
public static function create($userId, string $secret, int $expiration, string $issuer): string
    {
        $builder = self::builder();

        return $builder->setPayloadClaim('user_id', $userId)
            ->setSecret($secret)
            ->setExpiration($expiration)
            ->setIssuer($issuer)
            ->setIssuedAt(time())
            ->build()
            ->getToken();
    }