Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry Themes & Animated Graphics

Reply
Developer
Posts: 64
Registered: ‎05-06-2009
My Device: Not Specified
Accepted Solution

Sha Digest

Greetings


I am trying to do a Sha1 digest on a file and compare it to what I get doing a SHAi digest in php.


However, my SHA results are competely different between php and Blackberry


From blackberry, I do this


           SHA1Digest digest = new SHA1Digest();


            byte [] bytes = FileDirectories.readFileBytes(_filename);
            digest.update( bytes );
            byte[] digestValue = digest.getDigest();
            
            ret = ret + "\r\n";
            
            for (int i= 0; i < digestValue.length; i++)
            {
                byte b = digestValue[i];
                ret = ret +  Integer.toString(b & 0xff);
            }


From php, I do

echo sha1_file('Simulator_064.sdf');


Am I using the wrong SHAI Digest or using it incorretly>


Developer
Posts: 64
Registered: ‎05-06-2009
My Device: Not Specified

Re: Sha Digest

[ Edited ]

After about three hours testing, it appears that the problem is running the code on the simulator. When I run the code on a real blackberry, it works fine - when I run on the simulator, the SHA1 result is wrong if the size if the file is greater than about 400 bytes

 

BTW, I found an error in my code that failed to add an additional 0 in front of values with only one char, fixed like this


            byte b = digestValue[i];
            String h = Integer.toHexString(b & 0xff).toLowerCase();
            
            if (h.length() < 2)
            {
                h = "0" + h;
            }



That, however, had nothing to do with the problem