messagedigesit help

Heey.. posting here since I think it falls under secerity.

Im setting up an image database for over 1000 images. to be certain an image isnt used twice a friend of me advised to use message digest. I tried googling for tutorials and examples. googled this forum and read several docs I still cant figure out the exast working of this..

so no code yet

Anyone knows or has an example where messagedigist writes to images.txt the digest in md5 from c:/myimage.jpg.

or a how to or tutorial.. im not lazy, figured to post here after 3 hojurs of searching. so please. if you can. help.

Thanks

-Thijs Damen

[642 byte] By [Tjirpovfa] at [2007-10-2 15:09:00]
# 1

Yes java.security has a MessageDigest; if you do an internet search for "MD5 java" you'll find code.

A bit easier however is java.util.zip.CRC32, the 32bit checksum of every zip file entry.

Something like the following should do:

import java.io.*;

import java.util.zip.CRC32;

...

public static long getCRC(String file) throws IOException {

InputStream in = new BufferedInputStream(new FileInputStream(file));

CRC32 checksum = new CRC32();

for (;;) {

int c = in.read();

if (c == -1)

break;

checksum.update(c);

}

in.close();

return checksum.getValue();

}

joop_eggena at 2007-7-13 14:03:06 > top of Java-index,Other Topics,Algorithms...
# 2
hey, thanks for that. I googled some more stil lcoudnt find it though.Ill give your code a shot once I get home see what I get.Thanks
Tjirpovfa at 2007-7-13 14:03:06 > top of Java-index,Other Topics,Algorithms...