On 6/12/2014 6:15 AM, Frank Swarbrick wrote:
Does anyone know of a program/subroutine that can read "any kind" of MVS sequential 
dataset and calculate an MD5 hash on it?  By "any kind" I am specifically meaning a file 
that is either FB or VB and can have any LRECL.
We have created a program in COBOL to do this, with the problem that we have to 
have one program for each of the file format / LRECL lengths that we are 
looking at.  (I imagine we could have one program with multiple file 
definitions in it as well.)  COBOL has no file definition that is generic 
enough to support this.
We are using the ICSF 'CSNBOWH' (one way hash) function to do the actual MD5 
process.

I believe this could be done in assembler, but we don't have much assembler 
experience in house.  We would be open to a vendor product (in assembler or 
otherwise), or even just assembler source code (I think).
Thanks,Frank

I would go the other way and use Java instead of assembler. If you've got a zIIP it will definitely pay dividends. You will surprised just how efficient the latest z/OS Java is and you're more likely to find a Java programmer on the floor these days then
an assembler programmer.

IIRC, The z/OS Java SDK can use ICSF providers for MessageDigest.

The code is simple, even I can code it!

import com.ibm.jzos.RecordReader;
import com.ibm.jzos.ZFile;
import com.ibm.jzos.ZFileConstants;
import com.ibm.jzos.ZFileException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.math.BigInteger;

public class CalculateFileMD5 {

    public static void main(String[] args) {

        RecordReader reader = null;
        try {
reader = RecordReader.newReader("//DD:INPUT", ZFileConstants.FLAG_DISP_SHR);
            byte[] recordBuf = new byte[reader.getLrecl()];
            int bytesRead;
            MessageDigest md = MessageDigest.getInstance("MD5");
            while ((bytesRead = reader.read(recordBuf)) >= 0) {
                md.update(recordBuf, 0, bytesRead);
            }
            byte[] md5sum = md.digest();
System.out.println(String.format("%032X", new BigInteger(1, md5sum)));
        } catch (ZFileException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException cnse) {
            cnse.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (ZFileException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}


----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to