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*qzi\ 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

✰ BOE-HYDIS✰ Original HV150UX2-100 15" 4:3 1600x1200 UXGA LCD screen HV150UX2100
$329.95
✰ BOE-HYDIS✰ Original HV150UX2-100 1510pcs MAC97A8 LOGIC LEVEL TRIAC 600V 0.6 Amp 3-Pin TO-92
$2.5
10pcs MAC97A8 LOGIC LEVEL TRIAC 600V 0.6 Amp 3-Pin TO-92 picture3 x BLY84 transistor 250MHz (VHF power amp) NOS
$15.0
3 x BLY84 transistor 250MHz (VHF power amp) NOS pictureUNITRODE 3A201 TRANSISTOR NNB
$3.96
UNITRODE 3A201 TRANSISTOR NNB pictureUA78GUIC TRANSISTOR NNB
$1.96
UA78GUIC TRANSISTOR NNB picture






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