InputStream.toString()
probably doesn't do what you want it to. It's not overridden in the normal JDK, so it's basically Object.toString()
...which will return you a string like "java.io.InputStream@12345678"
. Even if Android's stuff did return a string representing the stream's contents, it'd get really weird since you never specify what encoding to use to convert bytes to chars.
You should read the stream in if you want to MD5 it. Kinda like
private static char[] hexDigits = "0123456789abcdef".toCharArray();
public String md5(InputStream is) throws IOException
{
byte[] bytes = new byte[4096];
int read = 0;
MessageDigest digest = MessageDigest.getInstance("MD5");
while ((read = is.read(bytes)) != -1)
{
digest.update(bytes, 0, read);
}
byte[] messageDigest = digest.digest();
StringBuilder sb = new StringBuilder(32);
// Oh yeah, this too. Integer.toHexString doesn't zero-pad, so
// (for example) 5 becomes "5" rather than "05".
for (byte b : messageDigest)
{
sb.append(hexDigits[(b >> 4) & 0x0f]);
sb.append(hexDigits[b & 0x0f]);
}
return sb.toString();
}