Java Code Examples for org.apache.tuweni.bytes.Bytes#update()

The following examples show how to use org.apache.tuweni.bytes.Bytes#update() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Hash.java    From besu with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to generate a digest using the provided algorithm.
 *
 * @param input The input bytes to produce the digest for.
 * @param alg The name of the digest algorithm to use.
 * @return A digest.
 */
private static byte[] digestUsingAlgorithm(final Bytes input, final String alg) {
  try {
    final MessageDigest digest = MessageDigestFactory.create(alg);
    input.update(digest);
    return digest.digest();
  } catch (final NoSuchAlgorithmException e) {
    throw new RuntimeException(e);
  }
}
 
Example 2
Source File: DepositGenerator.java    From teku with Apache License 2.0 4 votes vote down vote up
private Bytes sha256(final Bytes indexBytes) {
  final MessageDigest sha256Digest = getSha256Digest();
  indexBytes.update(sha256Digest);
  return Bytes.wrap(sha256Digest.digest());
}
 
Example 3
Source File: MockStartValidatorKeyPairFactory.java    From teku with Apache License 2.0 4 votes vote down vote up
private Bytes sha256(final Bytes indexBytes) {
  final MessageDigest sha256Digest = getSha256Digest();
  indexBytes.update(sha256Digest);
  return Bytes.wrap(sha256Digest.digest());
}
 
Example 4
Source File: Hash.java    From incubator-tuweni with Apache License 2.0 3 votes vote down vote up
/**
 * Helper method to generate a digest using the provided algorithm.
 *
 * @param input The input bytes to produce the digest for.
 * @param alg The name of the digest algorithm to use.
 * @return A digest.
 * @throws NoSuchAlgorithmException If no Provider supports a MessageDigestSpi implementation for the specified
 *         algorithm.
 */
public static Bytes digestUsingAlgorithm(Bytes input, String alg) throws NoSuchAlgorithmException {
  requireNonNull(input);
  requireNonNull(alg);
  MessageDigest digest = MessageDigest.getInstance(alg);
  input.update(digest);
  return Bytes.wrap(digest.digest());
}