用SHA1算法生成安全签名

@param array     字符串
@return 安全签名
@throws AesException
502980
public static String getSHA1(String... array) throws AesException {
        StringBuffer sb = new StringBuffer();
        // 字符串排序
        Arrays.sort(array);
        for(String item: array) {
            sb.append(item);
        }
        return getSHA1(sb.toString());
    }
927971
public function ascii($array) {

		$ascii = '';

		foreach ($array as $utf8) {
			if ($utf8 < 128) {
				$ascii .= chr($utf8);
			} elseif ($utf8 < 2048) {
				$ascii .= chr(192 + (($utf8 - ($utf8 % 64)) / 64));
				$ascii .= chr(128 + ($utf8 % 64));
			} else {
				$ascii .= chr(224 + (($utf8 - ($utf8 % 4096)) / 4096));
				$ascii .= chr(128 + ((($utf8 % 4096) - ($utf8 % 64)) / 64));
				$ascii .= chr(128 + ($utf8 % 64));
			}
		}

		return $ascii;

	}
715245
public static byte[] AesEncryptToBytes(byte[] content,byte[] encryptKey) throws Exception {
		KeyGenerator kgen = KeyGenerator.getInstance("AES");
		SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
		secureRandom.setSeed(encryptKey);
		kgen.init(128,secureRandom);
		Cipher cipher = Cipher.getInstance("AES");
		cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));
		return cipher.doFinal(content);
	}
1161
public function checkAuthArray($array)
	{

		//root
		if(array_has($array, 'root')){
			if(array_get($array, 'root') != 'only') {
				die('FooWeChat\Authorize\Auth\checkAuthArray: 参数 root 值错误');
			}
		}

		//admin
		if(array_has($array, 'admin')){
			$a = array_get($array, 'admin');
			if($a != 'yes' && $a != 'no' && $a != 'only') {
				die('FooWeChat\Authorize\Auth\checkAuthArray: 参数 admin 值错误');
			}
		}

		//way
		if(array_has($array, 'way')){
			$a = array_get($array, 'way');
			if($a != 'wechat' && $a != 'web' && $a != 'all') {
				die('FooWeChat\Authorize\Auth\checkAuthArray: 参数 way 值错误');
			}
		}

		//except
		if(array_has($array, 'except')){
			$this->checkUser(array_get($array, 'except'));
		}

		//user
		if(array_has($array, 'user')){
			$this->checkUser(array_get($array, 'user'));
		}

	}
665264
public com.google.protobuf.ByteString
      getSha1SumBytes() {
    java.lang.Object ref = sha1Sum_;
    if (ref instanceof java.lang.String) {
      com.google.protobuf.ByteString b = 
          com.google.protobuf.ByteString.copyFromUtf8(
              (java.lang.String) ref);
      sha1Sum_ = b;
      return b;
    } else {
      return (com.google.protobuf.ByteString) ref;
    }
  }
1190130
public static String HA1(String username, String realm, String password, String algorithm){
        String ha1 = "";
        ha1 = DigestAuthentication.H(username+":"+realm+":"+password, algorithm);
        return ha1;
    }
1186102
public static byte[] initKey() throws Exception{
		//密钥生成器
		KeyGenerator keyGen = KeyGenerator.getInstance("AES");
		//初始化密钥生成器
		keyGen.init(128);  //默认128，获得无政策权限后可用192或256
		//生成密钥
		SecretKey secretKey = keyGen.generateKey();
		return secretKey.getEncoded();
	}
1239053
protected function arrayToKey(array $array)
    {
        if ($this->isSequential($array)) {
            return $this->sequentialArrayToKey($array);
        }

        $parts = [];

        $keys = array_keys($array);
        sort($keys);

        foreach ($keys as $key) {
            $parts[] = $key;
            $parts[] = $this->castArrayValue($array[$key]);
        }

        return implode('_', $parts);
    }
1117613
public static String shaBase64(String s) {
    try {
      MessageDigest messageDigest = MessageDigest.getInstance("SHA-1");
      byte[] sha1Bytes = messageDigest.digest(s.getBytes("UTF-8"));
      return ByteString.of(sha1Bytes).base64();
    } catch (NoSuchAlgorithmException e) {
      throw new AssertionError(e);
    } catch (UnsupportedEncodingException e) {
      throw new AssertionError(e);
    }
  }
279852
public static String arrayToStringButSkipFirst(Object[] array) {
		if (array == null)
			DialectException.throwEX("StrUtils arrayToString() method do not accept null parameter");
		StringBuilder sb = new StringBuilder();
		int i = 1;
		for (Object object : array) {
			if (i++ != 1)
				sb.append("" + object + ",");

		}
		if (sb.length() > 0)
			sb.setLength(sb.length() - 1);
		return sb.toString();
	}
1161505
protected static String sha1(String... strings) {
        try {
            Arrays.sort(strings);
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            for (String s : strings) md.update(s.getBytes());
            return Utility.binToHexString(md.digest());
        } catch (Exception e) {
            throw new RuntimeException("SHA encryption to generate signature failure", e);
        }
    }
871357
public static byte[] HmacSha1(String plainText, String key) throws Exception {
		return HmacSha1(plainText.getBytes(), key);
	}
1160119
public static String sha1hmac(String key, String plaintext, int encoding)
	{
		byte[] signature = sha1hmac(key.getBytes(), plaintext.getBytes());

		return encode(signature, encoding);
	}
985587
def sha1(filename):
    """"""
    filename = unmap_file(filename)
    if filename not in file_cache:
        cache_file(filename)
        if filename not in file_cache:
            return None
        pass
    if file_cache[filename].sha1:
        return file_cache[filename].sha1.hexdigest()
    sha1 = hashlib.sha1()
    for line in file_cache[filename].lines['plain']:
        sha1.update(line.encode('utf-8'))
        pass
    file_cache[filename].sha1 = sha1
    return sha1.hexdigest()
356765
private static byte[] sha1(byte[] data) {
		MessageDigest md = null;
		try {
			md = MessageDigest.getInstance(ALGORITHM_SHA1);
			md.reset();
			md.update(data);
			return md.digest();
		} catch (Exception e) {
			LogUtil.writeErrorLog("SHA1计算失败", e);
			return null;
		}
	}
1094819
public static byte[] sha1(byte[] input) {
        MessageDigest messageDigest = sha1Digest.get();

        if (messageDigest == null) {
            try {
                messageDigest = MessageDigest.getInstance("SHA1");
                sha1Digest.set(messageDigest);
            } catch (NoSuchAlgorithmException e) {
                throw new UaRuntimeException(StatusCodes.Bad_InternalError, e);
            }
        }

        return messageDigest.digest(input);
    }
1113416
public static function arrayToKey(array $array): string {
        $result = "";
        \array_walk_recursive($array, function ($key, $value) use (&$result) {
            $result .= $key . $value;
        });
        return $result;
    }