Package org.eclipse.aether.util
Class StringDigestUtil
- java.lang.Object
-
- org.eclipse.aether.util.StringDigestUtil
-
public final class StringDigestUtil extends java.lang.Object
A simple digester utility for Strings. UsesMessageDigestfor requested algorithm. Supports one-pass or several rounds of updates, and as result emits hex encoded String.- Since:
- 1.9.0
-
-
Constructor Summary
Constructors Constructor Description StringDigestUtil(java.lang.String alg)Constructs instance with given algorithm.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringdigest()Returns the digest of all strings passed viaupdate(String)as hex string.static byte[]fromHexString(java.lang.String hexString)Creates a byte array out of hexadecimal representation of the specified bytes.static StringDigestUtilsha1()Helper method to createStringDigestUtilusing SHA-1 digest algorithm.static java.lang.Stringsha1(java.lang.String string)Helper method to calculate SHA-1 digest and hex encode it.static java.lang.StringtoHexString(byte[] bytes)Creates a hexadecimal representation of the specified bytes.StringDigestUtilupdate(java.lang.String data)Updates instance with passed in string.
-
-
-
Constructor Detail
-
StringDigestUtil
public StringDigestUtil(java.lang.String alg)
Constructs instance with given algorithm.- See Also:
sha1(),sha1(String)
-
-
Method Detail
-
update
public StringDigestUtil update(java.lang.String data)
Updates instance with passed in string.
-
digest
public java.lang.String digest()
Returns the digest of all strings passed viaupdate(String)as hex string. There is no state preserved and due implementation ofMessageDigest.digest(), same applies here: this instance "resets" itself. Hence, the digest hex encoded string is returned only once.- See Also:
MessageDigest.digest()
-
sha1
public static StringDigestUtil sha1()
Helper method to createStringDigestUtilusing SHA-1 digest algorithm.
-
sha1
public static java.lang.String sha1(java.lang.String string)
Helper method to calculate SHA-1 digest and hex encode it.
-
toHexString
public static java.lang.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 benull- Returns:
- the hexadecimal representation of the input or
nullif the input wasnull - Since:
- 2.0.0
-
fromHexString
public static byte[] fromHexString(java.lang.String hexString)
Creates a byte array out of hexadecimal representation of the specified bytes. If input string isnull,nullis returned. Input value must have even length (due hex encoding = 2 chars one byte).- Parameters:
hexString- the hexString to convert to byte array, may benull- Returns:
- the byte array of the input or
nullif the input wasnull - Since:
- 2.0.0
-
-