• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: URGENT, calculating MD5
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: URGENT, calculating MD5


  • Subject: Re: URGENT, calculating MD5
  • From: Mark Morris <email@hidden>
  • Date: Tue, 7 Mar 2006 11:49:05 -0600

Cool, this has the same effect as what I posted earlier, but it seems as though sun.misc.BASE64Encoder (which I was using) has long been deprecated, so I like Mike's solution.

Regards,
Mark

On Mar 7, 2006, at 11:31 AM, Mike Schrag wrote:

That's actually going to give you really funky results, because some of those bytes won't necessarily map to known characters in your current encoding. Here's the method I use:

  public static String toHexString(byte[] _digest) {
    StringBuffer hexString = new StringBuffer();
    for (int i = 0; i < _digest.length; i++) {
      String hexDigitStr = Integer.toHexString(0xFF & _digest[i]);
      if (hexDigitStr.length() == 1) {
        hexString.append("0");
      }
      hexString.append(hexDigitStr);
    }
    return hexString.toString();
  }


On Mar 7, 2006, at 12:07 PM, Timo Hoepfner wrote:

Hi,

AFAIK java's arrays don't override java.lang.Object's toString() method, so you get a textual representation of the internal object ID. To get a String from an array of bytes you should use the

public String(byte[] bytes)


constructor. So try

String calculatedMd5 = new String(result);

instead of result.toString().

HTH,

Timo

Am 06.03.2006 um 21:31 schrieb Amedeo Mantica:

my function:

String calculateMd5 (String message)
{
MessageDigest myMAC = MessageDigest.getInstance("MD5");

byte[] messageBytes=message.getBytes();
myMAC.update(messageBytes);
byte[] result = myMAC.digest();

String calculatedMd5=result.toString();
return calculatedMd5;
}

I ALWAYS GOT A STRING LIKE  "[B@6afa2"

any help?
Thanks
Amedeo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >URGENT, calculating MD5 (From: Amedeo Mantica <email@hidden>)
 >Re: URGENT, calculating MD5 (From: Timo Hoepfner <email@hidden>)
 >Re: URGENT, calculating MD5 (From: Mike Schrag <email@hidden>)

  • Prev by Date: jFreeChart
  • Next by Date: WODisplayGroup multiple sorting
  • Previous by thread: Re: URGENT, calculating MD5
  • Next by thread: Mac OS X Server on Intel Mac Minis?
  • Index(es):
    • Date
    • Thread