ECDSA-SHA256签名
@param string $data 需要签名的数据
@return string|bool 返回签名 失败时返回false
@throws SignatureException
@throws InvalidConfigException
967604
private function makeSignature($data)
    {
        $signature = '';
        $this->initOpenSSL();
        if (!openssl_sign($data, $signature, $this->privateKey, 'sha256')) {
            throw new SignatureException(openssl_error_string());
        }
        return $signature;
    }
531865
public function decrypt($data)
    {
        $data = base64_decode($data);

        $iv   = substr($data, 0, $this->ivSize);
        $hash = substr($data, $this->ivSize, 64);
        $enc  = substr($data, $this->ivSize + 64);

        $cleartext = rtrim(mcrypt_decrypt(
            MCRYPT_RIJNDAEL_256,
            $this->saltedKey,
            $enc,
            MCRYPT_MODE_CBC,
            $iv
        ), "\x00");

        // Needs to be after decrypt so it always runs, to avoid timing attack
        $gen_hash = hash_hmac('sha256', $enc, $this->saltedKey);

        if ($gen_hash == $hash) {
            return $cleartext;
        }
        return false;
    }
951069
private static byte[] sha256(byte[] data) {
		MessageDigest md = null;
		try {
			md = MessageDigest.getInstance(ALGORITHM_SHA256);
			md.reset();
			md.update(data);
			return md.digest();
		} catch (Exception e) {
			LogUtil.writeErrorLog("SHA256计算失败", e);
			return null;
		}
	}
15819
protected function getIffSignature($data)
	{
		$signature = substr($data, 0, self::LONG_SIZE);

		// Check if image is IFF
		if ($signature !== self::IFF_HEADER_AMIGA && $signature !== self::IFF_HEADER_MAYA)
		{
			return false;
		}
		else
		{
			return $signature;
		}
	}
649283
private static function sign($data, string $secret, string $algo='sha256')
  {
    return hash_hmac($algo, $data, $secret, false);
  }
250469
public function setFromData ($data)
	{
		// Check signature
		$model = $this;

		$chk = self::CHECK_SIGNATURE;

		if ($chk && !isset ($data['signature']))
		{
			throw new InvalidParameter ("All decoded requests must have a signature.");
		}

		if ($chk && $data['signature'] != self::calculateSignature ($data))
		{
			throw new InvalidParameter ("Leave now, and Never come Back! *gollem, gollem* (Decoded request signature mismatch).");
		}

		// The body. If data is found, body is not used.
		if (isset ($data['data']) && !empty ($data['data']))
		{
			$model->setData ($data['data']);
		}

		else if (isset ($data['body']))
		{
			$model->setBody ($data['body']);
		}

		if (isset ($data['headers']))
		{
			$model->setHeaders ($data['headers']);
		}

		if (isset ($data['cookies']))
		{
			$model->setCookies ($data['cookies']);
		}

		if (isset ($data['post']))
		{
			$model->setPost ($data['post']);
		}

		if (isset ($data['status']))
		{
			$model->setStatus ($data['status']);
		}

		return $model;
	}
1371219
public static function decrypt($data) : string {
      $crypter = new Crypter();

      return $crypter->decrypt($data, self::getAppKey());
    }
834915
public function sign(array $data)
    {
        ksort($data);

        $queryString = $this->buildQueryString($data);
        $data['h'] = base64_encode(hash_hmac('sha1', $queryString, $this->clientSecret, true));

        return $data;
    }
809239
function hash($data)
    {
        static $map = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $hash = bcadd(sprintf('%u', crc32($data)), 0x100000000);
        $str = '';
        do {
            $str = $map[bcmod($hash, 62)] . $str;
            $hash = bcdiv($hash, 62);
        } while ($hash >= 1);
        return $str;
    }
163250
public function encrypt($data)
    {
        try {
            return openssl_encrypt($data, self::$algorithm, self::$pass);
        } catch (\Exception $e) {
            return $data;
        }
    }
691937
public static function twoSha256($data, $binary = false)
    {
        return self::sha256(self::sha256($data, $binary), $binary);
    }
38130
public static function decode(string $data, string $secret )
  {
    # Make a HASH of the secret
    $secret = openssl_digest($secret,'sha256');

    $b64 = static::base64url_decode($data);
    $ewt = json_decode($b64,true);

    $payload = openssl_decrypt($ewt['p'], $ewt['a'], $secret, 0, $ewt['i']);

    # Verify signature - if fail return null
    if ( strcasecmp(static::sign($payload,$secret,$ewt['h']),$ewt['s'])!=0) {
      return null;
    }

    return $payload;
  }
1105132
protected function makeSignedRequest($data) {
    if (!is_array($data)) {
      throw new InvalidArgumentException(
        'makeSignedRequest expects an array. Got: ' . print_r($data, true));
    }
    $data['algorithm'] = self::SIGNED_REQUEST_ALGORITHM;
    $data['issued_at'] = time();
    $json = json_encode($data);
    $b64 = self::base64UrlEncode($json);
    $raw_sig = hash_hmac('sha256', $b64, $this->getAppSecret(), $raw = true);
    $sig = self::base64UrlEncode($raw_sig);
    return $sig.'.'.$b64;
  }
1195858
public static function seal(string $data): string
    {
        $publicKey = self::getPublicKey();
        
        // compute signature
        $sealed = null;
        $ekeys = array();
        
        $success = openssl_seal($data, $sealed, $ekeys, array(
            $publicKey
        ));
        if (!$success) {
            return $sealed;
        }
        
        $sealkey = $ekeys[0];
        
        // free the key from memory;
        openssl_free_key($publicKey);
        
        return self::base64UrlEncode($sealed) . '|' . self::base64UrlEncode($sealkey);
    }
728935
private static function getSignatureHash(string $data, string $salt, int $version = 2) : string
    {
        if ($version === 2) {
            return \base64_encode(\sodium_crypto_generichash($data, $salt, 64));
        }

        // Version 1 signature hash should be returned as a fallback
        return \hash('sha256', $data);
    }
402422
public function make_sign($data){
        /*去空*/
        $data=array_filter($data);
        /*签名步骤一：按字典序排序参数*/
        ksort($data);
        $string_a=http_build_query($data);
        $string_a=urldecode($string_a);

        /*签名步骤二：在string后加入KEY*/
        $config=$this->config;

        $string_sign_temp=$string_a."&key=".$config['key'];
        /*签名步骤三：MD5加密*/
        $sign = md5($string_sign_temp);
        /*签名步骤四：所有字符转为大写*/
        $result=strtoupper($sign);
        return $result;
    }
471761
public function sign($data)
    {
        $privateKeyResource = openssl_pkey_get_private('file://' . $this->filePath);

        $signature = null;
        openssl_sign($data, $signature, $privateKeyResource);

        openssl_free_key($privateKeyResource);

        return $signature;
    }