Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DigestInputStream - MD5 different results

843810Jun 9 2003 — edited Jun 12 2003
hi,
I saw a little example of DigestInputStream in the Internet, I tested it using a text-file , read it using :

while(dis.read(buffer) > 0)
;

Then I called the digest method and afterwards called an toHexString() method. After that I called md5sum and calculated the checksum of the same text file, but the result was different.

1) Can that be possible ?
2) If yes, how ?

SO far,
strychnin1

here is the code (without exception handling etc.)

FileInputStream fis = new FileInputStream(filename);
DigestInputStream dis = new DigestInputStream(fis,md);

byte[] buffer = new byte[1024];

while(dis.read(buffer) > 0)
;

byte[] digest = md5.digest();

fis.close();

Then I called the tohexstring() method, but that method is correct and can't be the reason for it.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 10 2003
Added on Jun 9 2003
10 comments
535 views