合并结果

@param sha1s 每块计算结果的列表
@return 最终的结果
197359
private static String resultEncode(byte[][] sha1s) {
        byte head = 0x16;
        byte[] finalHash = sha1s[0];
        int len = finalHash.length;
        byte[] ret = new byte[len + 1];
        if (sha1s.length != 1) {
            head = (byte) 0x96;
            MessageDigest sha1 = null;
            try {
                sha1 = MessageDigest.getInstance("sha-1");
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
                // never reach
                return null;
            }
            for (byte[] s : sha1s) {
                sha1.update(s);
            }
            finalHash = sha1.digest();
        }
        ret[0] = head;
        System.arraycopy(finalHash, 0, ret, 1, len);
        return UrlSafeBase64.encodeToString(ret);
    }
1106096
private static byte[] sha256(String datas, String encoding) {
		try {
			return sha256(datas.getBytes(encoding));
		} catch (UnsupportedEncodingException e) {
			LogUtil.writeErrorLog("SHA256计算失败", e);
			return null;
		}
	}
90223
public static String SHA1(String plainText) throws NoSuchAlgorithmException {
        // 返回值
        String result = null;
        // 是否是有效字符串
        if (StringUtils.isNotEmpty(plainText)) {
            // SHA 加密开始
            // 创建加密对象 并传入加密类型
            MessageDigest messageDigest = MessageDigest.getInstance(EncryptionType.SHA1);
            // 传入要加密的字符串
            messageDigest.update(plainText.getBytes());
            // 得到 byte 类型结果
            byte byteBuffer[] = messageDigest.digest();
            // 将 byte 转换为 string
            StringBuilder strHexString = new StringBuilder();
            // 遍历 byte buffer
            for (int i = 0; i < byteBuffer.length; i++) {
                String hex = Integer.toHexString(0xff & byteBuffer[i]);
                if (hex.length() == 1) {
                    strHexString.append('0');
                }
                strHexString.append(hex);
            }
            // 得到返回结果
            result = strHexString.toString();
        }
        return result;
    }
1202389
public static String getSHA1(String token, String timestamp, String nonce, String encrypt) throws AesException {
        try {
            String[] array = new String[]{token, timestamp, nonce, encrypt};
            StringBuffer sb = new StringBuffer();
            // 字符串排序
            Arrays.sort(array);
            for (int i = 0; i < 4; i++) {
                sb.append(array[i]);
            }
            String str = sb.toString();

            return getSHA1HexString(str);
        } catch (Exception e) {
            e.printStackTrace();
            throw new AesException(AesException.ComputeSignatureError);
        }
    }
572751
def sha1(str, lenght = 8)
      sha1 = Digest::SHA1.hexdigest(str)
      sha1[0, lenght.to_i]
    end
572747
def read_sha1(
    file_path,
    buf_size = None,
    start_byte = 0,
    read_size = None,
    extra_hashers = [], # update(data) will be called on all of these
):
    '''
    
    '''
    read_size = read_size or os.stat(file_path).st_size
    buf_size = buf_size or DEFAULT_BUFFER_SIZE

    data_read = 0
    total_sha1 = hashlib.sha1()
    while data_read < read_size:
        with open( file_path, 'rb', buffering = 0 ) as f:
            f.seek( start_byte )
            data = f.read( min(buf_size, read_size - data_read) )
            assert( len(data) > 0 )
            total_sha1.update( data )
            for hasher in extra_hashers:
                hasher.update( data )
            data_read += len(data)
            start_byte += len(data)
    assert( data_read == read_size )

    return total_sha1
309895
public static byte[] sha1(@NotNull String input, @Nullable byte[] salt, int iterations) {
		return digest(input.getBytes(Charsets.UTF_8), get(SHA_1_DIGEST), salt, iterations);
	}
844502
@Override
    public String hexSHA1(String value) {
        return String.valueOf(Hex.encodeHex(sha1(value)));
    }
1143194
func Sha1(c interface{}, version int) []byte {
	sum := sha1.Sum(Dump(c, version))
	return sum[:]
}
66524
public static String hashKey(String key) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA1");
            md.update(key.getBytes(StandardCharsets.UTF_8));
            md.update(MAGIC);
            return new String(B64Code.encode(md.digest()));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
1260364
protected function makeSoapClientHash()
    {
        return sha1(
            $this->request->getLocation()
            . json_encode($this->request->getOptions())
            . json_encode($this->request->getHeaders())
        );
    }
784135
def sha1_hash(string):
    '''
    
    '''

    hasher = sha1()
    hasher.update(string.encode())
    return hasher.hexdigest()
976261
public static String sha1Hash(File file) throws IOException {
        try {
            DigestInputStream inputStream = new DigestInputStream(
                    new FileInputStream(file), MessageDigest.getInstance("SHA-1"));
            try {
                byte[] buffer = new byte[4098];
                while (inputStream.read(buffer) != -1) {
                    // Read the entire stream
                }
                return bytesToHex(inputStream.getMessageDigest().digest());
            } finally {
                inputStream.close();
            }
        } catch (NoSuchAlgorithmException ex) {
            throw new IllegalStateException(ex);
        }
    }
1274627
def sha1(self):
        
        sha1 = hashlib.sha1(''.join(['%s:%s' % (k,v) for k,v in self.items()]))
        return str(sha1.hexdigest())
72897
private static String sha1hash(Collection<String> nquads) {
        try {
            // create SHA-1 digest
            final MessageDigest md = MessageDigest.getInstance("SHA-1");
            for (final String nquad : nquads) {
                md.update(nquad.getBytes("UTF-8"));
            }
            return encodeHex(md.digest());
        } catch (final NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        } catch (final UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
1220581
public static String sha1hmac(String key, String plaintext)
	{
		return sha1hmac(key, plaintext, ENCODE_HEX);
	}
825086
public String sha1() {
        try {
            final SecretKeySpec keySpec = new SecretKeySpec(secret.getPlainText().getBytes(UTF_8), HMAC_SHA1_ALGORITHM);
            final Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
            mac.init(keySpec);
            final byte[] rawHMACBytes = mac.doFinal(payload.getBytes(UTF_8));

            return Hex.encodeHexString(rawHMACBytes);
        } catch (Exception e) {
            LOGGER.error("", e);
            return INVALID_SIGNATURE;
        }
    }