Calculates the SHA-1 hash code of the input data and writes up to
20 bytes of it in the output byte array parameter.

@param data the byte array to be hashed
@param output output parameter for the calculated hash code
436501
public static void hash(byte[] data, byte[] output) {
    int len = output.length;
    if (len == 0)
      return;
    int[] code = calculate(data);
    for (int outIndex = 0, codeIndex = 0, shift = 24;
            outIndex < len && codeIndex < 5;
                ++outIndex, shift -= 8) {
      output[outIndex] = (byte) (code[codeIndex] >>> shift);
      if (shift == 0) {
        shift = 32;     // will be decremented by 8 before next iteration
        ++codeIndex;
      }
    }
  }
913764
public static byte[] computeSha256(final byte[] data) {
        try {
            return MessageDigest.getInstance(ALGORITHM_SHA_256).digest(data);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("unsupported algorithm for message digest: ", e);
        }
    }
384102
public static long createHash(byte[] data) {
        long h = 0;
        byte[] res;

        synchronized (digestFunction) {
            res = digestFunction.digest(data);
        }

        for (int i = 0; i < 4; i++) {
            h <<= 8;
            h |= ((int) res[i]) & 0xFF;
        }
        return h;
    }
574302
public final ChainResult calculateOutputHash(long level) throws KSIException {
        // TODO task KSIJAVAAPI-207 If the aggregation hash chain component contains the `input data' field, hash the value part of the field
        // using the hash algorithm specified by the first octet of the `input hash' field and verify that the result of
        // hashing `input data' equals `input hash'; terminate with a consistency error if they do not match.(spec. 4.1.1.2)

        // TODO task KSIJAVAAPI-207 if current aggregation hash chain isn't the first component of the hash chain and the chain
        // contains 'input data' field then terminate with a format error. (spec 4.1.1.2)

        DataHash lastHash = inputHash;
        long currentLevel = level;
        for (AggregationChainLink aggregationChainLink : chain) {
            ChainResult step = aggregationChainLink.calculateChainStep(lastHash.getImprint(), currentLevel, aggregationAlgorithm);
            lastHash = step.getOutputHash();
            currentLevel = step.getLevel();
        }
        this.outputHash = lastHash;
        return new InMemoryChainResult(lastHash, currentLevel);
    }
969919
public static int fnvHash(String data) {
		final int p = 16777619;
		int hash = (int) 2166136261L;
		for (int i = 0; i < data.length(); i++) {
			hash = (hash ^ data.charAt(i)) * p;
		}
		hash += hash << 13;
		hash ^= hash >> 7;
		hash += hash << 3;
		hash ^= hash >> 17;
		hash += hash << 5;
		return hash;
	}
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);
	}
1279327
def _hash_outputs(self, index, sighash_type):
        '''
        '''
        if sighash_type == shared.SIGHASH_ALL:
            # If the sighash type is ALL,
            # hashOutputs is the double SHA256 of all output amounts
            # paired up with their scriptPubKey;
            outputs = ByteData()
            for tx_out in self.tx_outs:
                outputs += tx_out.to_bytes()
            return utils.hash256(outputs.to_bytes())
        elif (sighash_type == shared.SIGHASH_SINGLE
              and index < len(self.tx_outs)):
            # if sighash type is SINGLE
            # and the input index is smaller than the number of outputs,
            # hashOutputs is the double SHA256 of the output at the same index
            return utils.hash256(self.tx_outs[index].to_bytes())
        else:
            # Otherwise, hashOutputs is a uint256 of 0x0000......0000
            raise NotImplementedError(
                'I refuse to implement the SIGHASH_SINGLE bug.')
846004
@Override
  public void write(DataOutput out) throws IOException {
    Text.writeString(out, getHostName());
    out.writeInt(getNumCpu());
    out.writeDouble(getCpuTotalGHz());
    out.writeDouble(getMemTotalGB());
    out.writeDouble(getCpuUsageGHz());
    out.writeDouble(getMemUsageGB());
  }
20449
public static int hash(byte[] data, int offset, int length, int seed) {
	    return hash(ByteBuffer.wrap(data, offset, length), seed);
	  }
856596
public static byte[] hash(byte[] data, int offset, int len) {
        try {
            MessageDigest a = MessageDigest.getInstance("SHA-256");
            a.update(data, offset, len);
            return a.digest();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }
1063431
public void write(final DataOutput output) throws IOException {
        output.write(ManagementProtocol.SIGNATURE);
        output.writeByte(ManagementProtocol.VERSION_FIELD);
        output.writeInt(getVersion());
        output.writeByte(ManagementProtocol.TYPE);
        output.writeByte(getType());
    }
1145968
public void write(final String data) throws IOException {
        if (socket != null) {
            out.write(data.getBytes());
        }
    }
730049
@Override
	public byte[] calculateSHA256HMAC(byte[] data, int offset, int length,
			byte[] aKey) {
		return BCHmacAdapter.hmac(data, offset, length, aKey, "HmacSHA256");
	}
956027
@SneakyThrows(IOException.class)
	public static String sha1(String input) throws NoSuchAlgorithmException {
		MessageDigest mDigest = MessageDigest.getInstance("SHA1");
		byte[] result = mDigest.digest(input.getBytes("UTF-8"));
		String resultString = String.format("%040x", new BigInteger(1, result));
		return resultString;
	}
1103889
public static byte[] sha1(byte[] data) {
        try {
            //Attempt to get a MessageDigest that uses SHA1
            MessageDigest md = MessageDigest.getInstance("SHA1");
            //Hash the data
            return md.digest(data);
        } catch (NoSuchAlgorithmException e) {
            //Alright, you might have an old system.
            throw new InternalError("SHA-1 is not supported on this platform - Outdated?");
        }
    }
586168
function(data, keysize) {
      var input, mode;
      if (keysize == null) {
        keysize = 512;
      }
      data = this.toHex(data);
      mode = "SHA-" + keysize;
      input = new jsSHA(data, "HEX");
      return input.getHash(mode, "HEX");
    }
1123396
public static void write(final String data, final OutputStream output) throws IOException {
		if (data != null) {
			output.write(data.getBytes(Charsets.UTF_8));
		}
	}