MD5 Decryption in Java
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 35

Thread: MD5 Decryption in Java

  1. #1
    Join Date
    Jan 2010
    Posts
    161

    MD5 Decryption in Java

    Hello everyone ,
    First of all I would like to compliment everyone because this forum is really nice and it does provide so many information.
    I have a task to perform and I would like to know if is possible to decrypt a hash key to know the original string value.
    As far as I can see by browsin is that this is not possible and the only way to this is to encrypt and compare hashes.
    Can someone tell if there is a way to decrypt MD5 hash keys or in a way or other find out whats the hash key is using java ?

    thank you in advance

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: MD5 Decryption in Java

    You can't decrypt the MD5 hash value as its a one way process. However, if the MD5 algorithm produced a different hash value for every possible input (which it doesn't), it would be possible to discover the original string. The simplest approach would be to try every possible input until you found the one that produced the same hash value - this might take some time though!! Of course even after many hours of computing you may just find an MD5 collision rather than the original message.

    There may be a better approach to discovering the original message but I'm no expert on cryptography. Maybe someone else can provide a more detailed response.

  3. #3
    Join Date
    Jan 2010
    Posts
    161

    Re: MD5 Decryption in Java

    yeah thanks for you answers, as i was expecting md5 cannot be decrypt.
    Therefore I would like to ask if there is a java classs and some tutorial that explain how to make md5 hashes and then compare them to the one which needs to be decrypt

    I already know which is going to be answer
    like some questions give me the md5 hash and ask me to find the original value by statin that is a 3 digit integer number between 100-999
    other ask me to find an equation ....
    so is it there any class that makes md5 hashes for strings we are looking for?

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: MD5 Decryption in Java

    It's time to use that wonderful tool called google.

    Just search for something like "Java MD5" and read some of the hits.

  5. #5
    Join Date
    Jan 2010
    Posts
    161

    Re: MD5 Decryption in Java

    thank you guys
    I have tried to load an MD5 ENCRYPTER and then use it to make comparisons so whenever it finds the to equal strings it will give me an output, however it does not give me the right MD5 output
    this is the code

    import java.security.*;

    public class MD5Encrypt {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    boolean chk=false;
    String hash,id;
    hash="F61D6947467CCD3AA5AF24DB320235DD"; //this is the hash key that I want to decrypt and the original value of this is 375

    hash=hash.toLowerCase();


    for (int i=100; i<=999;i++) /* over here i do a loop that start from 100 to 999 so it will generat hash keys for all the numbers and while it generates them it will also compare them in a method */
    {
    id=Integer.toString(i);

    md5Enc(id,hash, chk);
    if (chk==true)
    {
    break;
    }

    }
    }

    static void md5Enc (String sessionid, String hashKey,boolean found)
    {

    //sessionid="12345";

    byte[] defaultBytes = sessionid.getBytes();
    try{
    MessageDigest algorithm = MessageDigest.getInstance("MD5");
    algorithm.reset();
    algorithm.update(defaultBytes);
    byte messageDigest[] = algorithm.digest();

    StringBuffer hexString = new StringBuffer();
    for (int i=0;i<messageDigest.length;i++) {
    hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
    }
    String foo = messageDigest.toString();

    String generatedKey=hexString.toString();

    if (generatedKey.equals(hashKey)) /this is the comparison
    /but when it generates the hash key for
    { /375 it does generate a different hash
    System.out.println("The original value of the MD5 Hash "+ hashKey +" is : " + sessionid);
    found=true;

    }
    //String key1,key2;
    //key1=hashKey;
    //key2=hexString.toString();
    //


    //System.out.println("sessionid "+sessionid+" md5 version is "+hexString.toString());
    //sessionid=hexString+"";
    }catch(NoSuchAlgorithmException nsae){

    }
    }

    }



    -------------------------------------------------
    please help me with this/

  6. #6
    Join Date
    Feb 2008
    Posts
    966

    Re: MD5 Decryption in Java

    People don't generally want to take wild guesses at what is wrong. What is the output it is generating? What is the output that you are expecting? What do YOU think is happening? Have you tried to narrow it down at all?

  7. #7
    Join Date
    Jan 2010
    Posts
    161

    Re: MD5 Decryption in Java

    There is something wrong with the generation of the mD5 HASHES,and this is the reason why I cannot figured it out as it is a class that I am loading and found out from the enternet as someone suggested it in this forum.

    The value is 375 and the hash is :f61d6947467ccd3aa5af24db32235dd
    I know this because I checked it on internet.
    I want to decrypt the hash f61d6947467ccd3aa5af24db32235dd so I know the originale value(375)
    as is not possible to decrypt it ,the only way is to generate hashes for every single number and then compare them which is what i have done but when it generates the value for 375 it does give me this value instead :>>>> f61d6947467ccd3aa5af24db320235dd

  8. #8
    Join Date
    May 2009
    Location
    Surrey, UK
    Posts
    285

    Re: MD5 Decryption in Java

    The result you get (f61d6947467ccd3aa5af24db320235dd) has 32 hex digits and the hash you claim corresponds to 375 (f61d6947467ccd3aa5af24db32235dd) has 31. Are you sure the latter is a valid hash? MD5 produces 128-bit=16-byte=32-hex digits hashes.

  9. #9
    Join Date
    Jan 2010
    Posts
    161

    Re: MD5 Decryption in Java

    so what are you saying that this hash is wrong > F61D6947467CCD3AA5AF24DB320235DD

    because this is the hash that it has been told me to decrypt and I am not gettin that value when I run the program to encrypt integer numbers

    What do you think is wrong in this case?

  10. #10
    Join Date
    May 2009
    Location
    Surrey, UK
    Posts
    285

    Re: MD5 Decryption in Java

    Quote Originally Posted by cpu2007 View Post
    There is something wrong with the generation of the mD5 HASHES,and this is the reason why I cannot figured it out as it is a class that I am loading and found out from the enternet as someone suggested it in this forum.

    The value is 375 and the hash is :f61d6947467ccd3aa5af24db32235dd
    I know this because I checked it on internet.
    I want to decrypt the hash f61d6947467ccd3aa5af24db32235dd so I know the originale value(375)
    as is not possible to decrypt it ,the only way is to generate hashes for every single number and then compare them which is what i have done but when it generates the value for 375 it does give me this value instead :>>>> f61d6947467ccd3aa5af24db320235dd
    You said that this hash is wrong. You posted two hashes saying the first one is the one you want to decrypt and the other one is the result you get with your method, implying it is wrong.

  11. #11
    Join Date
    Jan 2010
    Posts
    161

    Re: MD5 Decryption in Java

    exactly thats right ...so what is the problem here...how can i make it work right?

  12. #12
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: MD5 Decryption in Java

    The hash you 'checked on the internet' is exactly the same except for a single digit (0), and, coincidentally, is short by that same digit. So what does common sense tell you about the internet hash value?

    Good teaching is more a giving of the right questions than a giving of the right answers...
    J. Albers
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  13. #13
    Join Date
    Jan 2010
    Posts
    161

    Re: MD5 Decryption in Java

    I dont understand much of this
    The hash that has been given to me to be decrypted is 32 bytes and the one that has been generated through the MD5 java class is 21 bytes right?
    I do understand that at the end of the day they are similar,but how do I make them generate the same value as the question one.
    This time i knew that the hash original value was 375 but in the next questions I will not know the original values so I will need to compare the the hash that will be asked me to compare plus the generated hash and when they will be equal I will be able to know the original value.

  14. #14
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: MD5 Decryption in Java

    Quote Originally Posted by cpu2007 View Post
    The hash that has been given to me to be decrypted is 32 bytes and the one that has been generated through the MD5 java class is 21 bytes right?
    No - unless you're talking about some other hash value. You've posted two hashes, one of 32 bytes and one of 31 bytes. From your previous posts, the 32 byte one is the one you generated and the 31 byte one is the hash you 'checked on the internet'. Maybe the internet one is missing a byte - just a thought...

    Computers are like bikinis. They save people a lot of guesswork...
    Sam Ewing
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  15. #15
    Join Date
    Jan 2010
    Posts
    161

    Re: MD5 Decryption in Java

    This is one is one that has been given me by my tutor and he asked me to decrypt it withouth using internet.
    F61D6947467CCD3AA5AF24DB320235DD

    This is the one generated by using the code that I have posted in the previous thread
    f61d6947467ccd3aa5af24db32235dd

    --------------------------------------------------------------------------

    Now why are they different, i mean has my tutor given me a wrong hash? I don't think so as I put that hash on google it comes up with the value 375
    and furthermore when I use the code to generate the hashes it comes up with a different hash for 375.
    So I really want to know if the problem is in the code or where?

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center