Exemplo n.º 1
0
 /**
  * Gets the MD5 hash the data on the given InputStream.
  *
  * @param in byte array for which an MD5 hash is desired.
  * @return 32-character hex representation the data's MD5 hash.
  * @throws IOException if an I/O error occurs.
  */
 public static String getHashString(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.getHashString();
 }
Exemplo n.º 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();
 }
Exemplo n.º 3
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();
 }
Exemplo n.º 4
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();
 }