[android-beginners] Re: MD5 Hash is wrong
Hey guys, Thanks for all the replies. I am sending the hash in a URL to a website to verify the information being sent. Every time I sent it with the above hash, it didn't work. When I sent it with a hash from another source (like a website that creates hashes), it worked. Niko20, sorry I didn't reference the function. I didn't realize it wasn't a built in API. I imported another library for my project, and I guess it gets imported from there. I eventually used code similar to the sample you provided and it worked. Thanks for the suggestion. The code I ended up using is: public static String MD5_Hash(String s) { MessageDigest m = null; try { m = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } m.update(s.getBytes(),0,s.length()); String hash = new BigInteger(1, m.digest()).toString(16); return hash; } On Dec 7, 1:55 pm, Kevin Duffey wrote: > Dan Niko20, little uptight this morning? It's amazing what happens when > you're actually nice in responses instead of so harsh. If you're going to > help out, why send a 3rd reply with such an attitude. > > > > On Mon, Dec 7, 2009 at 12:36 PM, niko20 wrote: > > And what the hell is your "MD5_Hash" function look like anyway? > > That's not a built in android API. > > > Crimony, give some info next time! Obviously your MD5 function is > > messed up. > > > -niko > > > On Dec 7, 2:33 pm, niko20 wrote: > > > Try this: > > > > public String md5(String s) { > > > try { > > > // Create MD5 Hash > > > MessageDigest digest = java.security.MessageDigest.getInstance > > > ("MD5"); > > > digest.update(s.getBytes()); > > > byte messageDigest[] = digest.digest(); > > > > // Create Hex String > > > StringBuffer hexString = new StringBuffer(); > > > for (int i=0; i > > hexString.append(Integer.toHexString(0xFF & messageDigest > > > [i])); > > > return hexString.toString(); > > > > } catch (NoSuchAlgorithmException e) { > > > e.printStackTrace(); > > > } > > > return ""; > > > > } > > > > Found it on google search > > > > On Dec 7, 2:32 pm, niko20 wrote: > > > > > Just a a side note, why do you care if it doesn't match? Unless you > > > > are comparing MD5's to ones generated elsewhere, you are still getting > > > > a unique hash. And as long as you compare to only hashes generated by > > > > android it will always match > > > > > -niko > > > > > On Dec 7, 1:14 pm, Justin Anderson wrote: > > > > > > Have you verified the website is correct by checking with a couple > > different > > > > > hash generation sites? > > > > > > On Dec 6, 2009 11:00 PM, "Mike M" wrote: > > > > > > Hey guys, > > > > > > I'm trying to get an MD5 Hash in my Android app, but it's not giving > > > > > the correct hash. > > > > > > For example, in my app I have this: > > > > > > MD5_Hash hash = new MD5_Hash(); > > > > > myHash = hash.Hash("What I want to Hash"); > > > > > > I get this from the above code: 306a801b82d299c8e965c2bf1d7fc18 > > > > > > I go to a website that will calculate MD5 hashes, and enter "What I > > > > > want to Hash", and get this: 306a8001b82d299c8e965c2bf1d7fc18. > > > > > > It does this every time; for some reason it strips one of the 0's. > > > > > Has anyone noticed this? Is there another / bettter way to get a > > hash > > > > > ? > > > > > > Thanks > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > > > Groups "Android Beginners" group. > > > > > To post to this group, send email to > > android-beginners@googlegroups.com > > > > > To unsubscribe from this group, send email to > > > > > android-beginners+unsubscr...@googlegroups.com > > > > i...@googlegroups.com> > i...@googlegroups.com> > > > > > For more options, visit this group athttp:// > > groups.google.com/group/android-beginners?hl=en > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Beginners" group. > > To post to this group, send email to android-beginners@googlegroups.com > > To unsubscribe from this group, send email to > > android-beginners+unsubscr...@googlegroups.com > i...@googlegroups.com> > > For more options, visit this group at > >http://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Re: MD5 Hash is wrong
The problem is Integer.toHexString(0xFF & messageDigest... It doeasn't print leading 0s try this one try { MessageDigest digest = java.security.MessageDigest.getInstance ("MD5"); digest.update(password.getBytes()); byte passDigest[] = digest.digest(); // Create Hex String StringBuffer hexPass = new StringBuffer(); for (int i=0; i wrote: > Try this: > > public String md5(String s) { > try { > // Create MD5 Hash > MessageDigest digest = java.security.MessageDigest.getInstance > ("MD5"); > digest.update(s.getBytes()); > byte messageDigest[] = digest.digest(); > > // Create Hex String > StringBuffer hexString = new StringBuffer(); > for (int i=0; i hexString.append(Integer.toHexString(0xFF & messageDigest > [i])); > return hexString.toString(); > > } catch (NoSuchAlgorithmException e) { > e.printStackTrace(); > } > return ""; > > } > > Found it on google search > > On Dec 7, 2:32 pm, niko20 wrote: > > > Just a a side note, why do you care if it doesn't match? Unless you > > are comparing MD5's to ones generated elsewhere, you are still getting > > a unique hash. And as long as you compare to only hashes generated by > > android it will always match > > > -niko > > > On Dec 7, 1:14 pm, Justin Anderson wrote: > > > > Have you verified the website is correct by checking with a couple > > > different > > > hash generation sites? > > > > On Dec 6, 2009 11:00 PM, "Mike M" wrote: > > > > Hey guys, > > > > I'm trying to get an MD5 Hash in my Android app, but it's not giving > > > the correct hash. > > > > For example, in my app I have this: > > > > MD5_Hash hash = new MD5_Hash(); > > > myHash = hash.Hash("What I want to Hash"); > > > > I get this from the above code: 306a801b82d299c8e965c2bf1d7fc18 > > > > I go to a website that will calculate MD5 hashes, and enter "What I > > > want to Hash", and get this: 306a8001b82d299c8e965c2bf1d7fc18. > > > > It does this every time; for some reason it strips one of the 0's. > > > Has anyone noticed this? Is there another / bettter way to get a hash > > > ? > > > > Thanks > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Android Beginners" group. > > > To post to this group, send email to android-beginners@googlegroups.com > > > To unsubscribe from this group, send email to > > > android-beginners+unsubscr...@googlegroups.com > > i...@googlegroups.com> > > > For more options, visit this group > > > athttp://groups.google.com/group/android-beginners?hl=en > > -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
Re: [android-beginners] Re: MD5 Hash is wrong
Dan Niko20, little uptight this morning? It's amazing what happens when you're actually nice in responses instead of so harsh. If you're going to help out, why send a 3rd reply with such an attitude. On Mon, Dec 7, 2009 at 12:36 PM, niko20 wrote: > And what the hell is your "MD5_Hash" function look like anyway? > That's not a built in android API. > > Crimony, give some info next time! Obviously your MD5 function is > messed up. > > -niko > > On Dec 7, 2:33 pm, niko20 wrote: > > Try this: > > > > public String md5(String s) { > > try { > > // Create MD5 Hash > > MessageDigest digest = java.security.MessageDigest.getInstance > > ("MD5"); > > digest.update(s.getBytes()); > > byte messageDigest[] = digest.digest(); > > > > // Create Hex String > > StringBuffer hexString = new StringBuffer(); > > for (int i=0; i > hexString.append(Integer.toHexString(0xFF & messageDigest > > [i])); > > return hexString.toString(); > > > > } catch (NoSuchAlgorithmException e) { > > e.printStackTrace(); > > } > > return ""; > > > > } > > > > Found it on google search > > > > On Dec 7, 2:32 pm, niko20 wrote: > > > > > > > > > Just a a side note, why do you care if it doesn't match? Unless you > > > are comparing MD5's to ones generated elsewhere, you are still getting > > > a unique hash. And as long as you compare to only hashes generated by > > > android it will always match > > > > > -niko > > > > > On Dec 7, 1:14 pm, Justin Anderson wrote: > > > > > > Have you verified the website is correct by checking with a couple > different > > > > hash generation sites? > > > > > > On Dec 6, 2009 11:00 PM, "Mike M" wrote: > > > > > > Hey guys, > > > > > > I'm trying to get an MD5 Hash in my Android app, but it's not giving > > > > the correct hash. > > > > > > For example, in my app I have this: > > > > > > MD5_Hash hash = new MD5_Hash(); > > > > myHash = hash.Hash("What I want to Hash"); > > > > > > I get this from the above code: 306a801b82d299c8e965c2bf1d7fc18 > > > > > > I go to a website that will calculate MD5 hashes, and enter "What I > > > > want to Hash", and get this: 306a8001b82d299c8e965c2bf1d7fc18. > > > > > > It does this every time; for some reason it strips one of the 0's. > > > > Has anyone noticed this? Is there another / bettter way to get a > hash > > > > ? > > > > > > Thanks > > > > > > -- > > > > You received this message because you are subscribed to the Google > > > > Groups "Android Beginners" group. > > > > To post to this group, send email to > android-beginners@googlegroups.com > > > > To unsubscribe from this group, send email to > > > > android-beginners+unsubscr...@googlegroups.com i...@googlegroups.com> > > > > For more options, visit this group athttp:// > groups.google.com/group/android-beginners?hl=en > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > To post to this group, send email to android-beginners@googlegroups.com > To unsubscribe from this group, send email to > android-beginners+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-beginners?hl=en > -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Re: MD5 Hash is wrong
And what the hell is your "MD5_Hash" function look like anyway? That's not a built in android API. Crimony, give some info next time! Obviously your MD5 function is messed up. -niko On Dec 7, 2:33 pm, niko20 wrote: > Try this: > > public String md5(String s) { > try { > // Create MD5 Hash > MessageDigest digest = java.security.MessageDigest.getInstance > ("MD5"); > digest.update(s.getBytes()); > byte messageDigest[] = digest.digest(); > > // Create Hex String > StringBuffer hexString = new StringBuffer(); > for (int i=0; i hexString.append(Integer.toHexString(0xFF & messageDigest > [i])); > return hexString.toString(); > > } catch (NoSuchAlgorithmException e) { > e.printStackTrace(); > } > return ""; > > } > > Found it on google search > > On Dec 7, 2:32 pm, niko20 wrote: > > > > > Just a a side note, why do you care if it doesn't match? Unless you > > are comparing MD5's to ones generated elsewhere, you are still getting > > a unique hash. And as long as you compare to only hashes generated by > > android it will always match > > > -niko > > > On Dec 7, 1:14 pm, Justin Anderson wrote: > > > > Have you verified the website is correct by checking with a couple > > > different > > > hash generation sites? > > > > On Dec 6, 2009 11:00 PM, "Mike M" wrote: > > > > Hey guys, > > > > I'm trying to get an MD5 Hash in my Android app, but it's not giving > > > the correct hash. > > > > For example, in my app I have this: > > > > MD5_Hash hash = new MD5_Hash(); > > > myHash = hash.Hash("What I want to Hash"); > > > > I get this from the above code: 306a801b82d299c8e965c2bf1d7fc18 > > > > I go to a website that will calculate MD5 hashes, and enter "What I > > > want to Hash", and get this: 306a8001b82d299c8e965c2bf1d7fc18. > > > > It does this every time; for some reason it strips one of the 0's. > > > Has anyone noticed this? Is there another / bettter way to get a hash > > > ? > > > > Thanks > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Android Beginners" group. > > > To post to this group, send email to android-beginners@googlegroups.com > > > To unsubscribe from this group, send email to > > > android-beginners+unsubscr...@googlegroups.com > > i...@googlegroups.com> > > > For more options, visit this group > > > athttp://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Re: MD5 Hash is wrong
Try this: public String md5(String s) { try { // Create MD5 Hash MessageDigest digest = java.security.MessageDigest.getInstance ("MD5"); digest.update(s.getBytes()); byte messageDigest[] = digest.digest(); // Create Hex String StringBuffer hexString = new StringBuffer(); for (int i=0; i wrote: > Just a a side note, why do you care if it doesn't match? Unless you > are comparing MD5's to ones generated elsewhere, you are still getting > a unique hash. And as long as you compare to only hashes generated by > android it will always match > > -niko > > On Dec 7, 1:14 pm, Justin Anderson wrote: > > > > > Have you verified the website is correct by checking with a couple different > > hash generation sites? > > > On Dec 6, 2009 11:00 PM, "Mike M" wrote: > > > Hey guys, > > > I'm trying to get an MD5 Hash in my Android app, but it's not giving > > the correct hash. > > > For example, in my app I have this: > > > MD5_Hash hash = new MD5_Hash(); > > myHash = hash.Hash("What I want to Hash"); > > > I get this from the above code: 306a801b82d299c8e965c2bf1d7fc18 > > > I go to a website that will calculate MD5 hashes, and enter "What I > > want to Hash", and get this: 306a8001b82d299c8e965c2bf1d7fc18. > > > It does this every time; for some reason it strips one of the 0's. > > Has anyone noticed this? Is there another / bettter way to get a hash > > ? > > > Thanks > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Beginners" group. > > To post to this group, send email to android-beginners@googlegroups.com > > To unsubscribe from this group, send email to > > android-beginners+unsubscr...@googlegroups.com > i...@googlegroups.com> > > For more options, visit this group > > athttp://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en
[android-beginners] Re: MD5 Hash is wrong
Just a a side note, why do you care if it doesn't match? Unless you are comparing MD5's to ones generated elsewhere, you are still getting a unique hash. And as long as you compare to only hashes generated by android it will always match -niko On Dec 7, 1:14 pm, Justin Anderson wrote: > Have you verified the website is correct by checking with a couple different > hash generation sites? > > On Dec 6, 2009 11:00 PM, "Mike M" wrote: > > Hey guys, > > I'm trying to get an MD5 Hash in my Android app, but it's not giving > the correct hash. > > For example, in my app I have this: > > MD5_Hash hash = new MD5_Hash(); > myHash = hash.Hash("What I want to Hash"); > > I get this from the above code: 306a801b82d299c8e965c2bf1d7fc18 > > I go to a website that will calculate MD5 hashes, and enter "What I > want to Hash", and get this: 306a8001b82d299c8e965c2bf1d7fc18. > > It does this every time; for some reason it strips one of the 0's. > Has anyone noticed this? Is there another / bettter way to get a hash > ? > > Thanks > > -- > You received this message because you are subscribed to the Google > Groups "Android Beginners" group. > To post to this group, send email to android-beginners@googlegroups.com > To unsubscribe from this group, send email to > android-beginners+unsubscr...@googlegroups.com i...@googlegroups.com> > For more options, visit this group > athttp://groups.google.com/group/android-beginners?hl=en -- You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en