Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

MD5 Encrypt in java

  • 26-02-2009 11:52PM
    #1
    Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭


    Hi
    How would I go about MD5 encrypting a string in java?
    I have a password which is encrypted in MD5 in a database so Id like to match the password entered in by the user with the MD5 encrypted password in the database and if they match then the user is logged in.

    So for the check in my java code for the query I tried
    Select * from users where user_name="+username+" and password="+MD5Crypt(password)

    That doesn't work because it's wrong.
    Java surely has some built in function to md5 encrypt a string hasn't it?
    Can you help?
    thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 222 ✭✭mecco


    if you look at the class in this link: http://www.anyexample.com/programming/java/java_simple_class_to_compute_md5_hash.xml, you should be able to see how to use the MD5 capabilities built into Java. I havent tested the class, but it appears to compute the hash for you and convert the byte array (provided by the default Java class) into a string. It gives an example how to call the code too.

    Again I havent tested it so your mileage may vary :)


  • Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭quinnd6


    Thanks that works grand.


  • Registered Users, Registered Users 2 Posts: 555 ✭✭✭baztard


    I'd be careful there, MD5 is a message digest / hash generally used to check if a file has changed or been tampered with in transit. I'm no expert but I dont think it should be used for encrypting passwords.


  • Closed Accounts Posts: 8,015 ✭✭✭CreepingDeath


    baztard wrote: »
    I'd be careful there, MD5 is a message digest / hash generally used to check if a file has changed or been tampered with in transit. I'm no expert but I dont think it should be used for encrypting passwords.

    One way hashing of passwords is more secure than encrypting.
    Encryption is a two way process, hashing / message digesting is a one way process. There's no way of working out the arbitrary length string from a fixed length digest without brute force.

    There's a clear difference between encryption and message digesting.


Advertisement