BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-11-2007, 02:53 PM   #1 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default md5 hashing

Please Login to Remove!

Hey all,
I'm attempting to md5 hash a value and am running into problems. What I thought would work
Code:
MD5Digest digest = new MD5Digest();
            digest.update(plainText);
            FWApp.log("digest: "+new String(digest.getDigest()));
yields something like qiD2ž*‰q¹Œzi\– which is not like any md5 hash I've ever seen. if I try the version suggested in the javadocs (below), I get basically the same thing. Has anyone done a successfull md5 (or other hash) and knows how to get the proper resultant?

javadoc ver:
Code:
 // sampleMD5Digest        
    private static int 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 );
        return digest.getDigestLength();
    }
Offline  
Old 08-22-2007, 07:35 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

The digest is 128 bits stored in a byte array 16 long. Most MD5 digests I've seen have been Base64 encoded. Have a look at Base64OutputStream and ByteArrayOutputStream.
Offline  
Old 08-22-2007, 11:05 PM   #3 (permalink)
Thumbs Must Hurt
 
Rose's Avatar
 
Join Date: Nov 2006
Location: India
Model: 9700
OS: Windows 7
Carrier: Airtel
Posts: 121
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Try to get the digest data which is normally a byte array of MD5 hash.

Convert the byte array in to a string.

Compare both the strings..

else do a base64 Conversion as suggested..
Offline  
Closed Thread


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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