2

i'm using MD5 hashing to encrypt passwords for a program. But it is not creating all the characters and that to some are unreadable. Here is an screenshot. link-http://i46.tinypic.com/2qvf2o2.jpg

Any help is appreciated

Thanks IMG

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Shalzz
  • 83
  • 1
  • 1
  • 7
  • 3
    'US-CERT now says that MD5 "should be considered cryptographically broken and unsuitable for further use."': http://en.wikipedia.org/wiki/MD5 (Just trying to save you some grief down the road. Easy to switch to something better now, possibly harder to do so later, after falling victim to an attack.) – DavidO Jul 20 '12 at 20:10
  • Lol, and nobody has yet said "Silly hash, you're **not** encryption!" :-) –  Jul 20 '12 at 20:15
  • you should try sha algorithms it's more safer tha md5. – Nudier Mena Jul 20 '12 at 20:19
  • 1
    SHA1 is not strong enough nowadays. SHA2 can be good. He's dealing with passwords, so should be using an algorithm that introduces a "work factor" (blowfish for example). But giving security advice beyond "more research necessary" in SO comments is probably not going to be an effective means of covering the topic. – DavidO Jul 20 '12 at 20:23

3 Answers3

2

Presumably you want to convert the array of bytes returned by MD5 to a hexidecimal string for display. Something like d131dd02c5e6eec4.

Here's how you can do that:

In Java, how do I convert a byte array to a string of hex digits while keeping leading zeros?

Community
  • 1
  • 1
Eric J.
  • 147,927
  • 63
  • 340
  • 553
0

You're interpreting the bytes returned by MD5 as raw character data.
Since MD5 does not return bytes that represent characters, you get meaningless results.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

What you're getting back is a binary value. So it's a bunch of raw bytes that may or may not map to valid characters in your default codepage. What you should do is convert the byte[] to hex. You can use something like Apache Commons Codec to encode this. http://commons.apache.org/codec/apidocs/org/apache/commons/codec/binary/Hex.html#encodeHex(byte[])

hsanders
  • 1,913
  • 12
  • 22