Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is md5Hash calculated for com.google.appengine.api.blobstore.BlobInfo

We're trying to avoid saving duplicate files. However, our md5 result is always different from BlobInfo.

How we calculate it:

    MessageDigest messageDigest = java.security.MessageDigest.getInstance("MD5");
    digest = messageDigest.digest(bytes);
    String digestString = DigestUtils.md5Hex(digest);

It doesn't match:with (new BlobInfoFactory().loadBlobInfo(blobKey)).getMd5Hash();

Example mismatches:

google vs my own calculation:
8cdeb6db94bc4fd156e2975fd8ebbcf2 vs 9003b37afbf3637de96c35774069453f 
65a25dafcba58d16d58a9c7585cc3932 vs 52383159f7d27417d50121aaee2728b5 
5cccc2d690fdc0c254234d5526876b34 vs 8196da9b6733daa60e08d927693df483 

It is on production server. ( we didn't test dev environment )

like image 824
Tom Fishman Avatar asked Nov 23 '12 23:11

Tom Fishman


1 Answers

Sebastian Kreft is right in the above discussion in comments.

The code I copied is wrong. it should just be:

String digestString = DigestUtils.md5Hex(bytes);

Sebastian Kreft used the trick to verify empty file's md5 which should always be d41d8cd98f00b204e9800998ecf8427e!

like image 157
Tom Fishman Avatar answered Nov 02 '22 15:11

Tom Fishman