# Re: MD5 implementation

David Brownell (db@Eng)
Fri, 30 Oct 1998 13:21:10 -0800

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Jan Luehe: "Re: Need PKCS12 provider package."
- Previous message: Scott A. Boltz: "MD5 implementation"
- Maybe in reply to: Scott A. Boltz: "MD5 implementation"

"Scott A. Boltz" wrote:
>
> I having trouble getting a correct message digest for a file. Here is
> my source:
>
> byte[] temp = new byte[32];

You don't need to allocate this memory here ...

> int amountread;
> byte[] buffer = new byte[1024];
> md.reset();
> try
> {
> FileInputStream fis = new FileInputStream( filename );
> while( ( amountread = fis.read( buffer ) ) != -1 )
> {
> md.update( buffer );

Consider what happens if only three bytes are read ... you're
digesting lots of bytes that should be ignored.

> }
> temp = md.digest();
> System.out.println( " " + temp );

You should probably conver the number to a BigInteger and
then print it in hex.

> System.out.println( " " + md.getDigestLength() );
> fis.close();
>
> My output consists of an eleven digit number. The message digest
> between runs also changes. Any help would be much appreciated.

Try fixing the bugs noted above, and see how much that helps.

- Dave

> Scott

- Next message: Jan Luehe: "Re: Need PKCS12 provider package."
- Previous message: Scott A. Boltz: "MD5 implementation"
- Maybe in reply to: Scott A. Boltz: "MD5 implementation"