|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.rhq.core.util.MessageDigestGenerator
public class MessageDigestGenerator
An object that generates a message digest or hash for algorithms such as MD5 or SHA. This class is basically a
wrapper around MessageDigest and provides convenience methods making it easier to generate
hashes.
There are static methods in here that use MD5 as the default algorithm. If you want to use another
algorithm, instantiate an instance of this object and use its instance methods.
| Field Summary | |
|---|---|
static String |
MD5
you can pass this to the constructor to indicate you want to generate MD5 message digests |
static String |
SHA_256
you can pass this to the constructor to indicate you want to generate SHA 256 message digests |
| Constructor Summary | |
|---|---|
MessageDigestGenerator()
Creates a new MessageDigestGenerator object using MD5 as the default algorithm. |
|
MessageDigestGenerator(String algorithm)
Creates a new MessageDigestGenerator using the specified algorithm. |
|
| Method Summary | |
|---|---|
void |
add(byte[] bytes)
Use this to add more data to the set of data used to calculate the hash. |
void |
add(byte[] bytes,
int offset,
int length)
Use this to add more data to the set of data used to calculate the hash. |
void |
add(InputStream is)
Use this to add more data to the set of data used to calculate the digest. |
byte[] |
calcDigest(File file)
|
byte[] |
calcDigest(InputStream is)
|
byte[] |
calcDigest(String source_str)
|
byte[] |
calcDigest(URL url)
|
String |
calcDigestString(byte[] bytes)
|
String |
calcDigestString(File file)
|
String |
calcDigestString(InputStream is)
|
String |
calcDigestString(String source_str)
|
String |
calcDigestString(URL url)
|
byte[] |
getDigest()
After all the data has been added to the message digest via add methods, this method is used to finalize the digest calcualation and return the digest. |
static byte[] |
getDigest(File file)
Calculates the digest for a given file. |
static byte[] |
getDigest(InputStream is)
Returns the digest for the data found in the given stream. |
static byte[] |
getDigest(String source_str)
Calculates a digest for a given string. |
String |
getDigestString()
After all the data has been added to the message digest via add methods, this method is used to finalize the digest calcualation and return the digest as a String. |
static String |
getDigestString(File file)
Calculates the digest for a given file. |
static String |
getDigestString(InputStream is)
Similar to getDigest(InputStream), only this returns the digest as a String. |
static String |
getDigestString(String source_str)
Calculates a digest for a given string and returns the digest's String representation. |
static String |
getDigestString(URL url)
Calculates the digest for a given file. |
MessageDigest |
getMessageDigest()
Returns the MessageDigest object that is used to compute the digest. |
static void |
main(String[] args)
This can be used to generate the digest hash from the command line. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String MD5
public static final String SHA_256
| Constructor Detail |
|---|
public MessageDigestGenerator()
MessageDigestGenerator object using MD5 as the default algorithm.
MD5 is used as the default algorithm for backward compatibility. It originally only supported MD5 and has since
been refactored to support algortithms that are supported by your version of Java.
IllegalStateException - if the MD5 algorithm cannot be computed by the VMpublic MessageDigestGenerator(String algorithm)
algorithm - The algorithm to use (e.g., MD5, SHA-256)
IllegalStateException - if the algorithm is not supported by the VM| Method Detail |
|---|
public MessageDigest getMessageDigest()
MessageDigest object that is used to compute the digest.
public void add(InputStream is)
throws IOException
getDigest() to get the final value.
is - the stream whose data is to be part of the set of data from which the digest is to be calculated
IOException - if there was a problem reading from the streampublic void add(byte[] bytes)
getDigest() to get the final digest value.
If bytes is null, this method is a no-op and simply returns.
bytes - data to be part of the set of data from which the digest is to be calculated
public void add(byte[] bytes,
int offset,
int length)
getDigest() to get the final digest value.
If bytes is null, this method is a no-op and simply returns.
bytes - data to be part of the set of data from which the digest is to be calculatedoffset - the offset to start from in the array of byteslength - the number of bytes to use, starting at offsetpublic byte[] getDigest()
getDigestString() instead.
public String getDigestString()
getDigest() instead.
public static byte[] getDigest(InputStream is)
throws IOException
is - the stream whose data is to be used to calculate the digest
IOException - if failed to read the stream for some reason
public byte[] calcDigest(InputStream is)
throws IOException
IOException
public static String getDigestString(InputStream is)
throws IOException
getDigest(InputStream), only this returns the digest as a String.
is - the stream whose data is to be used to calculate the digest
IOException - if failed to read the stream for some reason
public String calcDigestString(InputStream is)
throws IOException
IOExceptionpublic static byte[] getDigest(String source_str)
source_str - the string whose contents will be used as the data to calculate the digest
RuntimeException - if a system error occurred - should never really happenpublic byte[] calcDigest(String source_str)
public static String getDigestString(String source_str)
source_str - the string whose contents will be used as the data to calculate the digest
public String calcDigestString(String source_str)
public static byte[] getDigest(File file)
throws IOException
file - the file whose contents are to be used to calculate the digest.
IOException - if the file could not be read or accessed
public byte[] calcDigest(File file)
throws IOException
IOException
public byte[] calcDigest(URL url)
throws IOException
IOException
public static String getDigestString(File file)
throws IOException
file - the file whose contents are to be used to calculate the digest.
IOException - if the file could not be read or accessed
public String calcDigestString(File file)
throws IOException
IOException
public String calcDigestString(byte[] bytes)
throws IOException
IOException
public static String getDigestString(URL url)
throws IOException
url - the URL whose contents are to be used to calculate the digest.
IOException - if the URL could not be read or accessed
public String calcDigestString(URL url)
throws IOException
IOException
public static void main(String[] args)
throws Exception
args - one and only one filename - may or may not be a .jar file.
Exception - if failed to compute the digest for some reason
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||