|
com.Ostermiller.util Java Utilities |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.Ostermiller.util.MD5
public class MD5
MD5 hash generator. More information about this class is available from ostermiller.org.
This class takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. It is conjectured that it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given pre-specified target message digest. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA.
For more information see RFC1321.
MD5OutputStream
,
MD5InputStream
Constructor Summary | |
---|---|
MD5()
Class constructor |
Method Summary | |
---|---|
byte[] |
getHash()
Gets this hash sum as an array of 16 bytes. |
static byte[] |
getHash(byte[] b)
Gets the MD5 hash of the given byte array. |
static byte[] |
getHash(File f)
Gets the MD5 hash of the given file. |
static byte[] |
getHash(InputStream in)
Gets the MD5 hash the data on the given InputStream. |
static byte[] |
getHash(String s)
Gets the MD5 hash of the given String. |
static byte[] |
getHash(String s,
String enc)
Gets the MD5 hash of the given String. |
String |
getHashString()
Returns 32-character hex representation of this hash. |
static String |
getHashString(byte[] b)
Gets the MD5 hash of the given byte array. |
static String |
getHashString(File f)
Gets the MD5 hash of the given file. |
static String |
getHashString(InputStream in)
Gets the MD5 hash the data on the given InputStream. |
static String |
getHashString(String s)
Gets the MD5 hash of the given String. |
static String |
getHashString(String s,
String enc)
Gets the MD5 hash of the given String. |
static void |
main(String[] args)
Command line program that will take files as arguments and output the MD5 sum for each file. |
void |
reset()
Reset the MD5 sum to its initial state. |
String |
toString()
Returns 32-character hex representation of this hash. |
void |
update(byte b)
Updates this hash with a single byte. |
void |
update(byte[] buffer)
Update this hash with the given data. |
void |
update(byte[] buffer,
int length)
Update this hash with the given data. |
void |
update(byte[] buffer,
int offset,
int length)
Update this hash with the given data. |
void |
update(String s)
Update this hash with a String. |
void |
update(String s,
String enc)
Update this hash with a String. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public MD5()
Method Detail |
---|
public static void main(String[] args)
args
- command line argumentspublic byte[] getHash()
public String getHashString()
public static byte[] getHash(byte[] b)
b
- byte array for which an MD5 hash is desired.
public static String getHashString(byte[] b)
b
- byte array for which an MD5 hash is desired.
public static byte[] getHash(InputStream in) throws IOException
in
- byte array for which an MD5 hash is desired.
IOException
- if an I/O error occurs.public static String getHashString(InputStream in) throws IOException
in
- byte array for which an MD5 hash is desired.
IOException
- if an I/O error occurs.public static byte[] getHash(File f) throws IOException
f
- file for which an MD5 hash is desired.
IOException
- if an I/O error occurs.public static String getHashString(File f) throws IOException
f
- file array for which an MD5 hash is desired.
IOException
- if an I/O error occurs.public static byte[] getHash(String s)
s
- String for which an MD5 hash is desired.
public static String getHashString(String s)
s
- String for which an MD5 hash is desired.
public static byte[] getHash(String s, String enc) throws UnsupportedEncodingException
s
- String for which an MD5 hash is desired.enc
- The name of a supported character encoding.
UnsupportedEncodingException
- If the named encoding is not supported.public static String getHashString(String s, String enc) throws UnsupportedEncodingException
s
- String for which an MD5 hash is desired.enc
- The name of a supported character encoding.
UnsupportedEncodingException
- If the named encoding is not supported.public void reset()
public String toString()
toString
in class Object
public void update(byte[] buffer, int offset, int length)
If length bytes are not available to be hashed, as many bytes as possible will be hashed.
buffer
- Array of bytes to be hashed.offset
- Offset to buffer array.length
- number of bytes to hash.public void update(byte[] buffer, int length)
If length bytes are not available to be hashed, as many bytes as possible will be hashed.
buffer
- Array of bytes to be hashed.length
- number of bytes to hash.public void update(byte[] buffer)
buffer
- Array of bytes to be hashed.public void update(byte b)
b
- byte to be hashed.public void update(String s)
s
- String to be hashed.public void update(String s, String enc) throws UnsupportedEncodingException
s
- String to be hashed.enc
- The name of a supported character encoding.
UnsupportedEncodingException
- If the named encoding is not supported.
|
com.Ostermiller.util Java Utilities |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2001-2012 by Stephen Ostermiller