Compute SHA-1 hash value for a given input stream.
@param in Input stream
@return SHA-1 hash value (array of 20 bytes).
456
static byte[] sha1(InputStream in) {
    try {
      MessageDigest md = MessageDigest.getInstance(SHA1_DIGEST); 
      byte[] buffer = new byte[4096];
      int bytes;
      while ( (bytes = in.read(buffer)) > 0) {
        md.update(buffer, 0, bytes);
      }
      return md.digest();
    }
    catch(NoSuchAlgorithmException | IOException e) {
      throw new InternalErrorException(e);
    }
  }
271503
@Override
    public int compareTo(Sha1Wrapper arg0) {
        if (arg0 == null) return 1;
        for (int i = 0; i < 20; i++) {
            int cmp = hashBytes[i] - arg0.hashBytes[i];
            if (cmp != 0) return cmp;
        }
        return 0;
    }
308949
private static byte[] getHash(byte[] value) {

        byte[] hash = new byte[value.length - Generate.SALT_BYTES];
        System.arraycopy(value, Generate.SALT_BYTES, hash, 0, hash.length);
        return hash;
    }
285443
public static byte[] hash(InputStream in) throws IOException {
        if (HASH_DIGEST == null) {
            throw new EvernoteUtilException(EDAM_HASH_ALGORITHM + " not supported", new NoSuchAlgorithmException(EDAM_HASH_ALGORITHM));
        }

        byte[] buf = new byte[1024];
        int n;
        while ((n = in.read(buf)) != -1) {
            HASH_DIGEST.update(buf, 0, n);
        }
        return HASH_DIGEST.digest();
    }
727828
public static String sha1( String string ) {
        try {
            byte[] sha1 = SecureHash.getHash(SecureHash.Algorithm.SHA_1, string.getBytes());
            return SecureHash.asHexString(sha1);
        } catch (NoSuchAlgorithmException e) {
            throw new SystemFailureException(e);
        }
    }
825278
def sha(file, use_sha_file=false)
      if use_sha_file and File.exists?("#{file}.sha1")
        # reading the file is faster than doing a hash, so we keep the hash in the file
        # then we read back and compare.  There is no reason to perform sha1 everytime
        begin
          File.open("#{file}.sha1", 'r') { |f| f.read().strip}
        rescue
          Digest::SHA1.file(File.expand_path(file)).hexdigest
        end
      else
        Digest::SHA1.file(File.expand_path(file)).hexdigest
      end
    end
152458
private static byte[] oneBlock(byte[] buffer, InputStream in, int len) throws IOException {
        MessageDigest sha1 = null;
        try {
            sha1 = MessageDigest.getInstance("sha-1");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            //never reach
            return null;
        }
        int buffSize = buffer.length;
        while (len != 0) {
            int next = buffSize > len ? len : buffSize;
            //noinspection ResultOfMethodCallIgnored
            in.read(buffer, 0, next);
            sha1.update(buffer, 0, next);
            len -= next;
        }

        return sha1.digest();
    }
941333
public static byte[] sha3(byte[] input, int start, int length) {
        Keccak256 digest =  new Keccak256();
        digest.update(input, start, length);
        return digest.digest();
    }
1230
def sha1_ft(t, b, c, d)
      return (b & c) | ((~b) & d) if t < 20
      return b ^ c ^ d if t < 40
      return (b & c) | (b & d) | (c & d) if t < 60
      b ^ c ^ d
    end
1122037
public MurmurHash hash(int input) {
		count++;

		input *= 0xcc9e2d51;
		input = Integer.rotateLeft(input, 15);
		input *= 0x1b873593;

		hash ^= input;
		hash = Integer.rotateLeft(hash, 13);
		hash = hash * 5 + 0xe6546b64;

		return this;
	}
437796
@Override
  public final byte[] calculateSha1(final byte[] pPublicKey) throws Exception {
    Digest sha1 = new SHA1Digest();
    sha1.update(pPublicKey, 0, pPublicKey.length);
    byte[] digest = new byte[sha1.getDigestSize()];
    sha1.doFinal(digest, 0);
    return digest;
  }
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;
		}
	}
571599
function SHA1_encode(source) { // @arg Uint8Array
                               // @ret Uint8Array
//{@dev
    $valid($type(source, "Uint8Array"), SHA1_encode, "source");
//}@dev

    var buffer = _createBufferWith64BytePadding(source);
    var hash   = _SHA1(buffer); // [a, b, c, d, e]
    var result = new Uint8Array(20);

    for (var ri = 0, hi = 0; hi < 5; ri += 4, ++hi) {
        result[ri    ] = hash[hi] >>> 24 & 0xff;
        result[ri + 1] = hash[hi] >>> 16 & 0xff;
        result[ri + 2] = hash[hi] >>>  8 & 0xff;
        result[ri + 3] = hash[hi]        & 0xff;
    }
    return result;
}
268186
public static Checksum checksum(InputStream in, Checksum checksum) throws IORuntimeException {
		Assert.notNull(in, "InputStream is null !");
		if (null == checksum) {
			checksum = new CRC32();
		}
		try {
			in = new CheckedInputStream(in, checksum);
			IoUtil.copy(in, new NullOutputStream());
		} finally {
			IoUtil.close(in);
		}
		return checksum;
	}
155781
public static byte[] computeMD5Hash(InputStream is) throws IOException {
        BufferedInputStream bis = new BufferedInputStream(is);
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            byte[] buffer = new byte[SIXTEEN_K];
            int bytesRead;
            while ( (bytesRead = bis.read(buffer, 0, buffer.length)) != -1 ) {
                messageDigest.update(buffer, 0, bytesRead);
            }
            return messageDigest.digest();
        } catch (NoSuchAlgorithmException e) {
            // should never get here
            throw new IllegalStateException(e);
        } finally {
            try {
                bis.close();
            } catch (Exception e) {
                LogFactory.getLog(Md5Utils.class).debug(
                        "Unable to close input stream of hash candidate: " + e);
            }
        }
    }
660092
private String hash(String string) {
        final String sha1Hex = DigestUtils.sha1Hex(string);
        return StringUtils.substring(sha1Hex, 0, 8);
    }
572751
def sha1(str, lenght = 8)
      sha1 = Digest::SHA1.hexdigest(str)
      sha1[0, lenght.to_i]
    end