|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.rhq.core.domain.util.MD5Generator
public class MD5Generator
An object that can be used to generate an MD5 hashcode (called a "digest") for files, streams or strings. 128 bit fingerprints are computed as described in R. Rivest, The MD5 Message-Digest Algorithm, RFC1321.
Constructor Summary | |
---|---|
MD5Generator()
Creates a new MD5Generator object. |
Method Summary | |
---|---|
void |
add(byte[] bytes)
Use this to add more data to the set of data used to calculate the MD5. |
void |
add(InputStream is)
Use this to add more data to the set of data used to calculate the MD5. |
byte[] |
getDigest()
After all the data has been added to the message digest via add(InputStream) , this method is used to
finalize the MD5 calcualation and return the MD5 hashcode. |
static byte[] |
getDigest(File file)
Calculates the MD5 for a given file. |
static byte[] |
getDigest(InputStream is)
Returns the MD5 hashcode for the data found in the given stream. |
static byte[] |
getDigest(String source_str)
Calculates an MD5 for a given string. |
String |
getDigestString()
After all the data has been added to the message digest via add(InputStream) or add(byte[])
this method is used to finalize the MD5 calcualation and return the MD5 hashcode as a String. |
static String |
getDigestString(File file)
Calculates the MD5 for a given file. |
static String |
getDigestString(InputStream is)
Similar to getDigest(InputStream) , only this returns the MD5 as a String. |
static String |
getDigestString(String source_str)
Calculates an MD5 for a given string and returns the MD5's String representation. |
MessageDigest |
getMessageDigest()
Returns the MessageDigest object that is used to compute the MD5. |
static void |
main(String[] args)
This can be used to generate the MD5 hashcode from the command line. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MD5Generator()
MD5Generator
object.
IllegalStateException
- if the MD5 algorithm cannot be computed by the VMMethod Detail |
---|
public MessageDigest getMessageDigest()
MessageDigest
object that is used to compute the MD5.
public void add(InputStream is) throws IOException
getDigest()
to get the final MD5 value.
is
- the stream whose data is to be part of the set of data from which the MD5 is to be calculated
IOException
- if there was a problem reading from the streampublic void add(byte[] bytes)
getDigest()
to get the final MD5 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 MD5 is to be calculatedpublic byte[] getDigest()
add(InputStream)
, this method is used to
finalize the MD5 calcualation and return the MD5 hashcode. You can get the String form of this MD5 hashcode if
you call getDigestString()
instead.
public String getDigestString()
add(InputStream)
or add(byte[])
this method is used to finalize the MD5 calcualation and return the MD5 hashcode as a String. You can get the
actual bytes of the MD5 hashcode if you call getDigest()
instead.
public static byte[] getDigest(InputStream is) throws IOException
getDigestString(InputStream)
instead.
is
- the stream whose data is to be used to calculate the MD5
IOException
- if failed to read the stream for some reasonpublic static String getDigestString(InputStream is) throws IOException
getDigest(InputStream)
, only this returns the MD5 as a String.
is
- the stream whose data is to be used to calculate the MD5
IOException
- if failed to read the stream for some reasonpublic static byte[] getDigest(String source_str)
source_str
- the string whose contents will be used as the data to calculate the MD5 hashcode
RuntimeException
- if a system error occurred - should never really happenpublic static String getDigestString(String source_str)
source_str
- the string whose contents will be used as the data to calculate the MD5 hashcode
public static byte[] getDigest(File file) throws IOException
file
- the file whose contents are to be used to calculate the MD5.
IOException
- if the file could not be read or accessedpublic static String getDigestString(File file) throws IOException
file
- the file whose contents are to be used to calculate the MD5.
IOException
- if the file could not be read or accessedpublic 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 MD5 for some reason
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |