Class StringDigestUtil

java.lang.Object
org.eclipse.aether.util.StringDigestUtil

public final class StringDigestUtil extends Object
A simple digester utility for Strings. Uses MessageDigest for requested algorithm. Supports one-pass or several rounds of updates, and as result emits hex encoded String.
Since:
1.9.0
  • Constructor Details

  • Method Details

    • update

      Updates instance with passed in string.
    • digest

      public String digest()
      Returns the digest of all strings passed via update(String) as hex string. There is no state preserved and due implementation of MessageDigest.digest(), same applies here: this instance "resets" itself. Hence, the digest hex encoded string is returned only once.
      See Also:
    • sha1

      public static StringDigestUtil sha1()
      Helper method to create StringDigestUtil using SHA-1 digest algorithm.
    • sha1

      public static String sha1(String string)
      Helper method to calculate SHA-1 digest and hex encode it.
    • toHexString

      public static String toHexString(byte[] bytes)
      Creates a hexadecimal representation of the specified bytes. Each byte is converted into a two-digit hex number and appended to the result with no separator between consecutive bytes.
      Parameters:
      bytes - The bytes to represent in hex notation, may be null.
      Returns:
      The hexadecimal representation of the input or null if the input was null.
      Since:
      2.0.0
    • fromHexString

      public static byte[] fromHexString(String hexString)
      Creates a byte array out of hexadecimal representation of the specified bytes. If input string is null, null is returned. Input value must have even length (due hex encoding = 2 chars one byte).
      Parameters:
      hexString - The hexString to convert to byte array, may be null.
      Returns:
      The byte array of the input or null if the input was null.
      Since:
      2.0.0