BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 05-09-2008, 05:38 AM   #1
goelectric
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: curve
PIN: N/A
Carrier: O2
Posts: 17
Default md5 hashing and MD5Digest revisited

Please Login to Remove!

In case anyone else falls down the hole of how to get a normal md5
string in Java:-

static public String sampleMD5Digest( byte[] plainText, byte[] digestData ) throws CryptoException, IOException
{

// Create an instance of the digest algorithm
MD5Digest digest = new MD5Digest();

// Create the digest output stream for easy use
DigestOutputStream digestStream = new DigestOutputStream( digest, null );

// Write the text to the stream
digestStream.write( plainText );

// Copy the digest data to the digestData byte array and
// return the length
digest.getDigest( digestData, 0 );

String md5s = new String("");
for (int i=0;i <16 ; i++)
{

if (((digestData[i]) & 0xff) < 16) //toHexString returns single digit!!
md5s +="0";
md5s += Integer.toHexString((digestData[i]) & 0xff);


}

return md5s;
}
Offline  
Old 05-09-2008, 06:53 AM   #2
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

Thanks for the snippet. Might be useful in the future.

Maybe a Mod can create a new sticky thread for collecting useful code snippets...
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Voice Activated Listening Device Audio 150 Day Battery Spy Recorder 16 GB picture

Voice Activated Listening Device Audio 150 Day Battery Spy Recorder 16 GB

$109.00



AVNET ULTRAZED SOM ZYNQ ULTRASCALE+ XCZU3EG SYSTEM ON MODULE -  picture

AVNET ULTRAZED SOM ZYNQ ULTRASCALE+ XCZU3EG SYSTEM ON MODULE -

$98.67



Avnet UltraZed-EG AES-ZU3EG-1-SOM-I-G Zynq UltraScale+ MPSoC System-on-Module picture

Avnet UltraZed-EG AES-ZU3EG-1-SOM-I-G Zynq UltraScale+ MPSoC System-on-Module

$129.99



SIMATIC, Memory Card, 4 Mbytes, 24 Mbytes, 256 Mbytes picture

SIMATIC, Memory Card, 4 Mbytes, 24 Mbytes, 256 Mbytes

$237.75



Nakajima WPT-160 Electronic Portable Typewriter with Display and Memory picture

Nakajima WPT-160 Electronic Portable Typewriter with Display and Memory

$279.99



New Factory Sealed AB 1756-L61 SER B ControlLogix 2MB Memory Controller 1756L61 picture

New Factory Sealed AB 1756-L61 SER B ControlLogix 2MB Memory Controller 1756L61

$304.69







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.