Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Whirlpool hash - weird output

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    20
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Whirlpool hash - weird output

    Hello, the thing is I found myself in the need for a whirlpool hash(don't ask why).

    The only place I could find it was the one from GNU.

    To get to the point, this is the code:
    Whirlpool wp = new Whirlpool();
     
    				String s = "The quick brown fox jumps over the lazy dog";
    				byte[] b = s.getBytes(Charset.forName("UTF-8"));
    				wp.update(b,0,43);
     
    				byte[] r = wp.digest();
     
    				String str = new String(r,Charset.forName("UTF-8"));
    				System.out.println("String:"+str);

    And I was hoping for a nice whirlpool hash but got this instead:
    String:<?R??XF
    ????n?g?Tl??H?po???????	m?
    5?F ??
    y?QhTM?|?I???

    If you need any additional information(I think I posted all that's needed) just ask me, I'm the one that needs help.

    Note: do not suggest other algorithms. It's not a security issue. The data which will be used is Whirlpool hashed and I can't loose the data.(Unless, there's a way to unhash whirlpool..)


  2. #2
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Whirlpool hash - weird output

    Quote Originally Posted by Bebras View Post
    but got this instead:
    String:<?R??XF
    ????n?g?Tl??H?po???????	m?
    5?F ??
    y?QhTM?|?I???
    Very in general, a byte[] obtained by any "hash" (or "digest") function is not something that is directly human-readable, because it contains raw bytes, that is, a sequence of bytes of any value in the range 0x00 to 0xFF.
    If you want (this is typical) obtain an hexadecimal format of this hash/digest, you have to do this yourself or with the help of some utility functions, like the Hex.encodeHexString method from Apache Commons Codec library.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  3. The Following User Says Thank You to andbin For This Useful Post:

    Bebras (January 10th, 2014)

  4. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    20
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Whirlpool hash - weird output

    Wow, I don't even know how to thankyou.
    I used the library you suggested and the normal output:
    3ccf8252d8bbb258460d9aa999c06ee38e67cb546cffcf48e9 1f700f6fc7c183ac8cc3d3096dd30a35b01f4620a1e3a20d79 cd5168544d9e1b7cdf49970e87f1
    The problem is solved.

  5. #4
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Whirlpool hash - weird output

    Quote Originally Posted by Bebras View Post
    3ccf8252d8bbb258460d9aa999c06ee38e67cb546cffcf48e9 1f700f6fc7c183ac8cc3d3096dd30a35b01f4620a1e3a20d79 cd5168544d9e1b7cdf49970e87f1
    Ok, this has sense! You have 128 hex digits, that means 64 bytes = 512 bits.
    Similar to what I see in Whirlpool hashes.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  6. #5
    Junior Member
    Join Date
    Jan 2014
    Posts
    20
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Whirlpool hash - weird output

    Blah, according to your link it hashes it with "Whirlpool-T", and it seems that I need the "Whirlpool-0". As I already tried using it and it seems that this hash generates a different output than I have stored.

    Although the main problem is solved, perhaps you know where I could find the "Whirlpool-0" hash library?

    EDIT: I found these libraries: http://www.jonelo.de/java/jacksum/ In their doccumentation they state that you can hash Whirlpool-0 and others. But it's the same library that I used before. I just can't find a way to tell it to use "Whirlpool-0" and not some other type...

  7. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    3,402
    My Mood
    Mellow
    Thanks
    83
    Thanked 472 Times in 463 Posts

    Default Re: Whirlpool hash - weird output

    According to this, "blah," a word commonly used to describe an emotional state in which the person feels a sense of having no hope; usually during a deep depression.

    Hyperbole, I hope.

  8. #7
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: Whirlpool hash - weird output

    Quote Originally Posted by Bebras View Post
    perhaps you know where I could find the "Whirlpool-0" hash library?
    The Bouncy Castle Crypto package seems to have Whirlpool digests. I don't know more.
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  9. #8
    Junior Member
    Join Date
    Jan 2014
    Posts
    20
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default Re: Whirlpool hash - weird output

    I'm not quite sure what did you want to say ,GregBranno, but I had no hope.

    Anyway. I re-checked and it seems I needede the newest version of whirlpool. By using the "jacksum" library I used the class "Whirlpool2003" and for now it seems it works

Similar Threads

  1. Hash Functions
    By Blueshark in forum Java Theory & Questions
    Replies: 3
    Last Post: July 2nd, 2012, 03:04 PM
  2. hash table probes
    By victorh in forum Collections and Generics
    Replies: 4
    Last Post: November 7th, 2011, 11:33 PM
  3. hash map iteration
    By uniqe_mohini in forum Member Introductions
    Replies: 2
    Last Post: September 10th, 2011, 10:14 AM
  4. VERY WEIRD OUTPUT... HELP PLEASE?
    By Medo Almasry in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 23rd, 2011, 10:02 AM
  5. Simple Input/Output program Acting weird
    By drexasaurus in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 19th, 2010, 01:15 PM