Generating the required hash value from the data, nonce and the other information that is nearly static
@param string $data
@param string $nonce
@return string
345904
protected function genHash($data, $nonce) {
		$token = $this->getConfig()->getStorage()->getAccessToken()->getAccessToken();
		return sha1(urlencode($data) . $this->getConfig()->getAppId() . urlencode(sha1($token)) . urlencode($nonce) . $this->getConfig()->getAppSecret() . $token);
	}
717388
def generate_nonce(length=8):
    """"""
    return ''.join([str(random.SystemRandom().randint(0, 9)) for i in range(length)])
49023
public static function header($data)
    {
        if (empty($data['response'])) {
            throw new NetException("Can't create Authorization headers from an empty response.");
        }
        if (!isset($data['nonce'])) {
            return "Basic " . $data['response'];
        }
        $defaults = [
            'realm' => 'app', 'method' => 'GET', 'uri' => '/',
            'username' => null, 'qop' => 'auth',
            'nonce' => null, 'opaque' => null,
            'cnonce' => md5(time()),  'nc' => static::$nc
        ];
        $data += $defaults;
        $auth = "username=\"{$data['username']}\", response=\"{$data['response']}\", ";
        $auth .= "uri=\"{$data['uri']}\", realm=\"{$data['realm']}\", ";
        $auth .= "qop=\"{$data['qop']}\", nc={$data['nc']}, cnonce=\"{$data['cnonce']}\", ";
        $auth .= "nonce=\"{$data['nonce']}\", opaque=\"{$data['opaque']}\"";
        return "Digest " . $auth;
    }
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);
    }
1024433
public function encryptMessage($message, $timestamp, $nonce) {
		$encrypt = $this->encrypt(XmlResponseFormatter::formatData($message));

		return [
			'Encrypt' => $encrypt,
			'MsgSignature' => $this->sign([$this->manager->app->token, $timestamp, $nonce, $encrypt]),
			'TimeStamp' => $timestamp,
			'Nonce' => $nonce,
		];
	}
306904
public function decrypt($data, Key $key)
	{
		// Validate key.
		if ($key->getType() !== 'sodium')
		{
			throw new InvalidKeyTypeException('sodium', $key->getType());
		}

		if (!$this->nonce)
		{
			throw new \RuntimeException('Missing nonce to decrypt data');
		}

		$decrypted = Compat::crypto_box_open(
			$data,
			$this->nonce,
			Compat::crypto_box_keypair_from_secretkey_and_publickey($key->getPrivate(), $key->getPublic())
		);

		if ($decrypted === false)
		{
			throw new \RuntimeException('Malformed message or invalid MAC');
		}

		return $decrypted;
	}
648831
public static function decode($data)
    {
        $params = [];
        while ($data) {
            // TODO take care of single byte length values
            // When the highest bit is 1 then 4 byte are used, else 1 byte
            // For both name and value
            /*if ($data[0] >> 7 === 1) {
                // 4 byte
            } else {
                // 1 byte
            }*/
            $header = \unpack('Nname/Nvalue', substr($data, 0, 8));
            $params[substr($data, 8, $header['name'] - 0x80000000)] = substr($data, 8 + $header['name'] - 0x80000000, $header['value'] - 0x80000000);
            $data = substr($data, 8 + ($header['name'] - 0x80000000) + ($header['value'] - 0x80000000));
        }

        return new self($params);
    }
1193117
public function createNonce()
    {
        $secret  = $this->getSecret();
        $timeout = $this->getLifetime();

        $nonce = $this->_createNonce($secret, $timeout);
        $this->nonces[$nonce] = $nonce;

        return $nonce;
    }
438531
protected function getNonceSalt()
    {
        // Allow users to set their own nonce
        if (!is_null($this->getConfig('nonce'))) {
            return $this->request->generateNonceKey($this->getConfig('nonce'));
        // Use the entity if it is present
        } elseif (!is_null($this->associatedEntity)) {
            return $this->request->generateNonceKey($this->associatedEntity);
        }

        // Fallback to something custom for the Helper
        return $this->request->generateNonceKey();
    }
1144652
public function verify_nonce($action, $key = '_wpnonce'){
		$nonce = $this->request($key);
		return $nonce && wp_verify_nonce($this->request($key), $action);
	}
865895
protected function _nonce($length = 8)
  {
    if ($length < 1) {
      throw new \Exception('Invalid nonce length.');
    }
    return substr(md5($this->_microtime(true)), 0, $length);
  }
1214838
protected function getNonce()
    {
        $nonce = '';

        // get 16 random bytes
        for ($i = 0; $i < 16; $i++) {
            $nonce .= chr(mt_rand(0, 255));
        }

        // base-64 encode them
        $nonce = base64_encode($nonce);

        return $nonce;
    }
821696
public function encrypt($xml, $nonce = null, $timestamp = null): string
    {
        try {
            $xml = $this->pkcs7Pad(str_random(16).pack('N', strlen($xml)).$xml.$this->appId, $this->blockSize);

            $encrypted = base64_encode(AES::encrypt(
                $xml,
                $this->aesKey,
                substr($this->aesKey, 0, 16),
                OPENSSL_NO_PADDING
            ));
            // @codeCoverageIgnoreStart
        } catch (Throwable $e) {
            throw new RuntimeException($e->getMessage(), self::ERROR_ENCRYPT_AES);
        }
        // @codeCoverageIgnoreEnd

        !is_null($nonce) || $nonce = substr($this->appId, 0, 10);
        !is_null($timestamp) || $timestamp = time();

        $response = [
            'Encrypt' => $encrypted,
            'MsgSignature' => $this->signature($this->token, $timestamp, $nonce, $encrypted),
            'TimeStamp' => $timestamp,
            'Nonce' => $nonce,
        ];

        //生成响应xml
        return XML::build($response);
    }
1144670
public function createNonceStr() {
        $chars  = "abcdefghijklmnopqrstuvwxyz0123456789";
        $str    = "";
        for ( $i = 0; $i < self::NONCE_STRING_LENGTH; $i++ ) {
            $str .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
        }

        return $str;
    }
3304
public function generateDigest($nonce, $createdAt, $password)
    {
        return base64_encode(sha1(base64_decode($nonce) . $createdAt . $password, true));
    }
1159879
public function setNonce($nonce = null)
    {
        $this->nonce = $nonce;
        if ($nonce === null) {
            $this->nonce = new Nonce();
        }
        return $this;
    }
666014
private function generateHash($data)
    {
        $key = $this->getConfig('apiKey');
        $hmac = base64_encode(hash_hmac('sha256', $data, $key, true));

        return strtr($hmac, array('+' => '-', '/' => '_', '=' => ''));
    }