Set secret, encode this secret with Hmac, SHA1 method

@param string $secret

@return Payload
500530
public function setSecret(string $secret): Payload
    {
        $this->secret = hash_hmac('sha1', $this->rawData, $secret);

        return $this;
    }
112185
protected function sign(array $parameters)
    {
        //turn into string and add the secret key to the end
        $signatureString = '';

        foreach ($parameters as $key => $value) {
            $signatureString .= $key . '=' . $value;
        }

        $signatureString .= $this->secret;

        return sha1($signatureString);
    }
625086
private function hmacsha1(string $key, string $message): string
    {
        if (function_exists('hash_hmac')) {
            return hash_hmac('sha1', $message, $key, true);
        }

        $blocksize = 64;
        if (strlen($key) > $blocksize) {
            $key = pack('H*', sha1($key));
        }
        $key = str_pad($key, $blocksize, chr(0x00));
        $ipad = str_repeat(chr(0x36), $blocksize);
        $opad = str_repeat(chr(0x5c), $blocksize);
        $hmac = pack('H*', sha1(($key ^ $opad).pack('H*', sha1(($key ^ $ipad).$message))));

        return $hmac;
    }
1359487
protected function encodeToken($claims, $secret, $hashMethod = 'HS256')
    {
        if (method_exists($encoder = $this->resolveEncoder(), 'encode')) {
            return call_user_func_array(array($encoder, 'encode'), array($claims, $secret, $hashMethod));
        }

        throw new MissingEncoderException('No JSON Web Token encoder could be found');
    }
1081379
public static function authenticateThenDecrypt($secret, $body, $signature) {
    $keys = self::deriveAesKeys($secret);

    $localHmac = hash_hmac('sha256', $body, $keys['auth']);
    if (!self::hash_compare($signature, $localHmac)) {
      throw new InvalidMessageException("Incorrect hash");
    }

    list ($jsonEnvelope, $jsonEncrypted) = explode(Constants::PROTOCOL_DELIM, $body, 2);
    if (strlen($jsonEnvelope) > Constants::MAX_ENVELOPE_BYTES) {
      throw new InvalidMessageException("Oversized envelope");
    }

    $envelope = json_decode($jsonEnvelope, TRUE);
    if (!$envelope) {
      throw new InvalidMessageException("Malformed envelope");
    }

    if (!is_numeric($envelope['ttl']) || Time::getTime() > $envelope['ttl']) {
      throw new InvalidMessageException("Invalid TTL");
    }

    if (!is_string($envelope['iv']) || strlen($envelope['iv']) !== Constants::AES_BYTES * 2 || !preg_match('/^[a-f0-9]+$/', $envelope['iv'])) {
      // AES_BYTES (32) ==> bin2hex ==> 2 hex digits (4-bit) per byte (8-bit)
      throw new InvalidMessageException("Malformed initialization vector");
    }

    $jsonPlaintext = UserError::adapt('Civi\Cxn\Rpc\Exception\InvalidMessageException', function () use ($jsonEncrypted, $envelope, $keys) {
      $cipher = new \Crypt_AES(CRYPT_AES_MODE_CBC);
      $cipher->setKeyLength(Constants::AES_BYTES);
      $cipher->setKey($keys['enc']);
      $cipher->setIV(BinHex::hex2bin($envelope['iv']));
      return $cipher->decrypt($jsonEncrypted);
    });
    return $jsonPlaintext;
  }
999844
public static function sign($msg, $secret)
    {
        $signature = hash_hmac("sha1", $msg, $secret, true);
        return strtr(
            base64_encode($signature),
            '/+', '_-'
        );
    }
797248
public function setS3($key = null, $secret = null) {
		$this->s3 = new \S3($key, $secret);
		$this->setCompress(true);
	}
219645
public function isValid($secret)
    {
        if (!extension_loaded('hash')) {
            // @codeCoverageIgnoreStart
            throw new \Exception('Hash extension not loaded');
            // @codeCoverageIgnoreEnd
        }

        list($algo, $sig) = explode("=", $this->signature);

        if (!in_array($algo, hash_algos(), true)) {
            throw new \Exception("Hash algorithm '$algo' is not supported.");
        }

        $hash = hash_hmac($algo, $this->rawBody, $secret);

        return (md5($sig) === md5($hash));
    }
68066
public function setBitbucketOAuth($key, $secret, $domain = 'bitbucket.org')
    {
        $this->set(
            self::BITBUCKET_OAUTH_KEY . '/' . $this->escape($domain),
            ['consumer-key' => $key, 'consumer-secret' => $secret]
        );

        return $this;
    }
325115
public static function decryptG($str, $secret = 'ePHP')
    {
        if (!$str) {
            return false;
        }

        $key = md5($secret . "30f7384ac1");

        $ciphertext_raw = \ePHP\Misc\Func::safe_b64decode($str);
        return openssl_decrypt($ciphertext_raw, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
    }
1339110
protected function hmacsha1($data, $blocksize = 64)
    {
        $key = urlencode($this->secretAcessKey);

        if (strlen($key) > $blocksize) {
            $key = pack('H*', sha1($key));
        }

        $key  = str_pad($key, $blocksize, chr(0x00));
        $ipad = str_repeat(chr(0x36), $blocksize);
        $opad = str_repeat(chr(0x5c), $blocksize);
        return pack('H*', sha1(($key^$opad).pack('H*', sha1(($key^$ipad).$data))));
    }
117323
public
    static function validate($uuid, $secret)
    {
        $uuidData = preg_replace('/[^0-9a-z]/i', '', $uuid);
        $uuidData = substr($uuidData, 8);

        $hash = hash_hmac(self::HASH_METHOD, $uuidData, $secret);
        $checksum = "b" . substr($hash, 0, 7);

        return $checksum == substr($uuid, 0, 8);
    }
333632
public static function encryptG($str, $secret = 'ePHP')
    {
        if (!$str) {
            return false;
        }

        $key = md5($secret . "30f7384ac1");

        $ciphertext_raw = openssl_encrypt($str, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
        return \ePHP\Misc\Func::safe_b64encode($ciphertext_raw);
    }
284203
private function secret($secret): void
    {
        if (false === is_array($secret) && false === is_string($secret)) {
            throw new InvalidArgumentException(
                'Secret must be either a string or an array of "kid" => "secret" pairs'
            );
        }
        $this->options["secret"] = $secret;
    }
589499
function(secret) {
        var keyIv;
        if (!secret) {
          throw new CError('missing secret').log();
        }
        // secret is a Base64 string
        if(secret.isBase64()){
          try {
            keyIv = forge.util.decode64(secret);
          } catch (e) {
            throw new CError('secret not valid').log();
          }
        } else {
          keyIv = secret;
        }
        return keyIv;
      }
405307
private static function hmacFallbackMD5($data, $secret) {
    $b = 64; // byte length for md5

    if (strlen($secret) > $b) {
      $secret = pack("H*", md5($secret));
    }

    $secret = str_pad($secret, $b, chr(0x00));
    $ipad = str_pad('', $b, chr(0x36));
    $opad = str_pad('', $b, chr(0x5c));
    $k_ipad = $secret ^ $ipad;
    $k_opad = $secret ^ $opad;

    return md5($k_opad . pack("H*", md5($k_ipad . $data)));
  }
1196934
public static function getInstance($secret, $apiHost)
    {
        if (!isset(self::$instances[$secret][$apiHost])) {
            self::$instances[$secret][$apiHost] = new self(
                new Entity\Factory(
                    new Client\Curl($secret, $apiHost)
                )
            );
        }

        return self::$instances[$secret][$apiHost];
    }