0

I want to encrypt a String using gnu.crypto.hash.Whirlpool hashing.

The encrypt should encrypt the password and should return the encrypted pwd. encrypt(pwd);

This method should have implementation for encrypting pwd using gnu jars and whirlpool
hashing algorithm which should be equal to the pwd generated by the below site http://hash.online-convert.com/whirlpool-generator

I tried with the code below but I am unable to get the 512 byets code similar to the whirlpool site generated:

import gnu.crypto.hash.HashFactory;
import gnu.crypto.hash.IMessageDigest;

  public class EncryptPwdWithAPI{
public static void main(String arg[])
{
         encrypt("somepwd");
    }
public static String encrypt(String password)
{
IMessageDigest md = HashFactory.getInstance("WHIRLPOOL");
md.update(input, 0, input.length); 
byte[] digest = md.digest(); 
System.out.println( "Input : "+new String(input)+ "\nPWD : "+new String(digest)
}

}

3
  • Please don't include a 'sig.' in posts, never include an email address, and show some effort of your own - SO is not a help-desk. Commented Aug 12, 2012 at 10:10
  • :) I tried with the below but I am unable to get the 512 byets code similar to the whirlpool site generated. IMessageDigest md = HashFactory.getInstance("WHIRLPOOL"); md.update(input, 0, input.length); byte[] digest = md.digest(); System.out.println( "Input : "+new String(input)+ "\nPWD : "+new String(digest) ); Commented Aug 12, 2012 at 10:26
  • When I use the bouncycastle library's implementation of Whirlpool I get the same output as PHP's. Commented Jun 29, 2014 at 23:07

3 Answers 3

3

Ya correct but i was expecting whirlpool hascode with 512 bytes which is equal to the code generated by the online hashcode generator. I got the intended output with JacksumAPI.

Here's some code:

import java.security.NoSuchAlgorithmException;

import jonelo.jacksum.JacksumAPI;
import jonelo.jacksum.algorithm.AbstractChecksum;

public class JacksumTest {
    public static void main(String arg[])
    {
        String password = "somepwd";
        AbstractChecksum checksum = null; 
        try { 
           checksum = JacksumAPI.getChecksumInstance("whirlpool"); 
           checksum.update(password.getBytes());
           System.out.println(checksum.getFormattedValue());
        } catch (NoSuchAlgorithmException nsae) { }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You are directly using the byte values as character values instead you should convert the byte array to hex or base64 encoding to compare it to the values on the whirlpool site. Apache Commons Codec provides hex and base64 functions.

import org.apache.commons.codec.binary.Base64;
...
  Base64.encodeBase64String(digest);

1 Comment

Thank you for the reply but it is not returning the result same as generated by [link] hash.online-convert.com/whirlpool-generator
0

@Eelke is correct, but This is how you do it, encoded password should be in the result variable.

    IMessageDigest oldencoder = HashFactory.getInstance(Registry.WHIRLPOOL_HASH);

    byte[] input = password.getBytes();

    oldencoder.update(input, 0, input.length);

    byte[] digest = oldencoder.digest();

    result = gnu.crypto.util.Util.toString(digest).toLowerCase();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.