|
Tom,
I use a simple Java program to do this. It works on large files. Here
is the source:
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* Generate an MD5 checksum and send it to STDOUT
* @author David Morris
*/
public class CheckSum {
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Usage: java CheckSum
<filepath>");
} else {
try {
System.out.println(Hex.encode(createMD5(new
File(args[0]))));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static byte[] createMD5(final File file)
throws NoSuchAlgorithmException, IOException {
InputStream inputStream = new FileInputStream(file);
MessageDigest md5 = MessageDigest.getInstance("MD5");
final byte[] buf = new byte[8192];
int bytes = 0;
while ((bytes = inputStream.read(buf)) != -1) {
md5.update(buf, 0, bytes);
}
inputStream.close();
return md5.digest();
}
static class Hex {
/**
* Convert a byte array into a printable format
containing a
* String of hexadecimal digit characters (two per
byte).
* @param bytes Byte array representation
*/
public static String encode(byte bytes[]) {
StringBuffer sb = new StringBuffer(bytes.length
* 2);
for (int i = 0; i < bytes.length; i++) {
sb.append(convertDigit((int) (bytes[i]
>> 4)));
sb.append(convertDigit((int) (bytes[i] &
0x0f)));
}
return (sb.toString());
}
/**
* [Private] Convert the specified value (0 .. 15) to
the corresponding
* hexadecimal digit.
*
* @param value Value to be converted
*/
private static char convertDigit(int value) {
value &= 0x0f;
if (value >= 10)
return ((char) (value - 10 + 'a'));
else
return ((char) (value + '0'));
}
}
}
I use this script to run it:
#!/bin/sh
saveclasspath=$CLASSPATH
export -s CLASSPATH=/java/somedirectory
java CheckSum $1
export -s CLASSPATH=$saveclasspath
David Morris
>>> qsrvbas@xxxxxxxxxxxx 03/31/05 5:07 PM >>>
Some general background...
The archive has this item which seems to have never been responded to:
http://archive.midrange.com/midrange-l/200302/msg00838.html
Also, Perl/php, Linux, various *nixes and who knows what else have
md5sum and other commands or utilities.
Under OS/400, we primarily have CIPHER or the _CIPHER builtin.
But I'm unclear about CIPHER (and probably MD5 to boot). It seems that
the maximum string length would be 16MB since a pointer is input to the
function. Some process for handling a document (streamfile) >16MB would
seem to require a chaining from segment to segment or something like
that.
A google over AIX and MD5 left me with a sea of references that will
take a month to go through to see if PASE might help. QShell didn't have
anything that jumped out at me.
Is there any material on how to handle >16MB documents under OS/400?
Thanks in advance.
Tom Liotta
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.