Example #1
0
 /**
  * Gets the MD5 hash the data on the given InputStream.
  *
  * @param in byte array for which an MD5 hash is desired.
  * @return Array of 16 bytes, the hash of all updated bytes.
  * @throws IOException if an I/O error occurs.
  */
 public static byte[] getHash(InputStream in) throws IOException {
   MD5 md5 = new MD5();
   byte[] buffer = new byte[1024];
   int read;
   while ((read = in.read(buffer)) != -1) {
     md5.update(buffer, read);
   }
   return md5.getHash();
 }
Example #2
0
 /**
  * Gets the MD5 hash of the given byte array.
  *
  * @param b byte array for which an MD5 hash is desired.
  * @return 32-character hex representation the data's MD5 hash.
  */
 public static String getHashString(byte[] b) {
   MD5 md5 = new MD5();
   md5.update(b);
   return md5.getHashString();
 }
Example #3
0
 /**
  * Gets the MD5 hash of the given byte array.
  *
  * @param b byte array for which an MD5 hash is desired.
  * @return Array of 16 bytes, the hash of all updated bytes.
  */
 public static byte[] getHash(byte[] b) {
   MD5 md5 = new MD5();
   md5.update(b);
   return md5.getHash();
 }
Example #4
0
 /**
  * Gets the MD5 hash of the given String.
  *
  * @param s String for which an MD5 hash is desired.
  * @param enc The name of a supported character encoding.
  * @return 32-character hex representation the data's MD5 hash.
  * @throws UnsupportedEncodingException If the named encoding is not supported.
  * @since ostermillerutils 1.00.00
  */
 public static String getHashString(String s, String enc) throws UnsupportedEncodingException {
   MD5 md5 = new MD5();
   md5.update(s, enc);
   return md5.getHashString();
 }
Example #5
0
 /**
  * Gets the MD5 hash of the given String. The string is converted to bytes using the current
  * platform's default character encoding.
  *
  * @param s String for which an MD5 hash is desired.
  * @return 32-character hex representation the data's MD5 hash.
  */
 public static String getHashString(String s) {
   MD5 md5 = new MD5();
   md5.update(s);
   return md5.getHashString();
 }
Example #6
0
 /**
  * Gets the MD5 hash of the given String. The string is converted to bytes using the current
  * platform's default character encoding.
  *
  * @param s String for which an MD5 hash is desired.
  * @return Array of 16 bytes, the hash of all updated bytes.
  */
 public static byte[] getHash(String s) {
   MD5 md5 = new MD5();
   md5.update(s);
   return md5.getHash();
 }