× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi list,

Here is the Md5 computation for String or Stream file.
Any ideas are welcome

* here is the cmd.      MD5
             CMD        PROMPT('Fingerprint MD5')

             PARM       KWD(DATA) TYPE(*CHAR) LEN(512) CASE(*MIXED) +
                          PROMPT('Data')
             PARM       KWD(TYPE) TYPE(*CHAR) LEN(7) RSTD(*YES) +
                          DFT(*STRING) VALUES(*STMF *STRING) +
                          CASE(*MIXED) PROMPT('Type')
* here is the cl        MD5CL
             PGM        PARM(&DATA &TYPE)
             DCL        VAR(&DATA) TYPE(*CHAR) LEN(512)
             DCL        VAR(&PRINT) TYPE(*CHAR) LEN(49)
             DCL        VAR(&TYPE) TYPE(*CHAR) LEN(7)

             CALL       PGM(MYMD5) PARM(&DATA &PRINT &TYPE)

             SNDPGMMSG  MSG('Fingerprint MD5:' *CAT &PRINT)
             RETURN
** Here is the main pgm Mymd5
     HBnddir('QC2LE')
     D/COPY PROTO1

     DMYMD5            PR
     DIntext_                              Like(Intext)
     DMmd5_                                Like(Mmd5)
     DType_                                Like(Type)

     DMYMD5            PI
     DIntext                        512
     DMmd5                           49
     DType                            7

     DStatds           DS
     D St_Size                21     24B 0

     DPtr              S               *
     DFd               S             10I 0
     DFd1              S             10I 0
     DStmf             S                   Like(Intext)
      /Free
       If Type = '*STRING';
        Mmd5 = Md5(%Addr(Intext):%Len(%Trim(Intext)):Type);
       Else;
        Stmf = %Trimr(Intext) + X'00';
        Fd   = Open(%Addr(Stmf):1);  // 1 for read only
        Fd1  = Lstat(%Addr(Stmf):%Addr(Statds)); // Get size
        Ptr  = %Alloc(St_Size);
        Fd1  = Read(Fd:Ptr:St_Size); // Read content
        Fd1  = close(Fd);
        Mmd5 = Md5(Ptr:St_Size:Type); // Perform md5
        Dealloc Ptr;
       Endif;
       Return;
      /End-free
** Here the Proto1 Copy
     DClose            PR            10I 0 ExtProc('close')
     D handle                        10I 0 value

     DRead             PR            10I 0 ExtProc('read')
     D handle                        10I 0 value
     D buffer                          *   value
     D bytes                         10U 0 value

     DOpen             PR            10I 0 ExtProc('open')
     D filename                        *   value
     D openflags                     10I 0 value
     D mode                          10U 0 value options(*nopass)
     D codepage                      10U 0 value options(*nopass)

     DLstat            PR            10I 0 ExtProc('lstat')
     D path                            *   Value
     D buf                             *   Value
     D
     Dcvthc            PR                  ExtProc('cvthc')
     D ChrVal                        32A   Options(*VarSize)
     D HexVal                        16A   Options(*VarSize)
     D ChrLgt                        10I 0 Value

     DQtqcvrt          PR                  Extpgm('QTQCVRT')
     DCCSID1_                        10I 0
     DST1_                           10I 0
     DStartMap_                     256
     DL1_                            10I 0
     DCCSID2_                        10I 0
     DST2_                           10I 0
     DGCCASN_                        10I 0
     DL2_                            10I 0
     DTo819_                        256
     DL3_                            10I 0
     DL4_                            10I 0
     DFB_                            12A
     D
     Dcipher           PR                  extproc('_CIPHER')
     D                                 *   value
     D                                 *   value
     D                                 *   value
     D
     Dconvert          PR                  extproc('_XLATEB')
     D                                 *   value
     D                                 *   value
     D                               10u 0 value
     D
     DMD5              PR            49a   Extproc('MD5')
     D Inputdata                       *   Value
     D InputLength                   10I 0 Const
     D Type                           7A   Const
** Here is the srvpgm  mysrv
     H NoMain bnddir('QC2LE')
     D/COPY PROTO1

     PMD5              B                   Export
     C*-- Procedure interface
     DMD5              PI            49A
     D Inputdata                       *   Value
     D Inputlength                   10I 0 Const
     D Type                           7A   Const

     D
     DUpper            C                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
     DLower            C                   'abcdefghijklmnopqrstuvwxyz'
     D*-- Variables for _CIPHER MI
     DHashworkarea     S             96A   Inz(*Allx'00')
     DReceiverhex      S             16A   Inz
     DReceiverptr      S               *   Inz(%Addr(Receiverhex))
     D*-- Variables for output
     DReceiverchr      S             32A
     DReceived         S             49A
     D*-- Variables for QTQCVRT API
     DStartmap         S            256A   Inz
     DTo819            S            256A   Inz
     DCcsid1           S             10I 0 Inz(37)
     DSt1              S             10I 0 Inz(0)
     DL1               S             10I 0 Inz(%Size(Startmap))
     DCcsid2           S             10I 0 Inz(819)
     DSt2              S             10I 0 Inz(0)
     DGccasn           S             10I 0 Inz(0)
     DL2               S             10I 0 Inz(%Size(To819))
     DL3               S             10I 0 Inz
     DL4               S             10I 0 Inz
     DFb               S             12A   Inz
     D*-- Control data structure for _CIPHER MI
     DControls         DS
     D Function                       5I 0 Inz(5)
     D Hashalg                        1A   Inz(X'00')
     D Sequence                       1A   Inz(X'00')
     D Datalength                    10I 0 Inz(15)
     D Unused                         8A   Inz(*Loval)
     D Hashctxptr                      *   Inz(%Addr(Hashworkarea))
     D*-- Data structure for EBCDIC/ASCII prep
     D                 DS
     DX                               5I 0
     D Lowx                    2      2
      /Free
       If Type = '*STRING';
       // Get all single byte ebcdic hex values
        For X = 0 To 255;
         %Subst(StartMap:x+1:1) = LowX;
        EndFor;
        // Get conversion table for 819 from 37
        Qtqcvrt(Ccsid1:St1:StartMap:L1:Ccsid2:St2:Gccasn:L2:To819:L3:L4:
                       Fb);
        // Change message to ccsid 819 (ascii).
        Convert(Inputdata:%Addr(To819):InputLength);
       Endif;
       Hashworkarea = *AllX'00';
       // Hashctxptr = %Addr(Hashworkarea);
       // Get MD5 fingerprint of data
       Datalength = InputLength;
       Cipher(%Addr(Receiverptr):%Addr(Controls):%Addr(Inputdata));
       Cvthc(Receiverchr:Receiverhex:%Size(Receiverchr));
       // In the *NIX and PC world, letters found in MD5 are in lower case
       Receiverchr = %Xlate(Upper:Lower:Receiverchr);
       Received    = *Blank;
       For X = 1 By 2 to 31;
        Received = %Trimr(Received) + ':' + %Subst(Receiverchr:X:2);
       Endfor;
       %Subst(Received:1:1)= '[';
       Received = %Trimr(Received) + ']';
       Return Received;
      /End-Free
     PMD5              E
Compilation
CRTCMD CMD(MD5) PGM(MD5CL) SRCFILE(QCMDSRC)
CRTBNDCL PGM(MD5CL) SRCFILE(QCLESRC)
CRTRPGMOD MODULE(MD5SRV) SRCFILE(QRPGLESRC)
CRTRPGMOD MODULE(MYMD5) SRCFILE(QRPGLESRC)
CRTSRVPGM SRVPGM(MD5SRV) EXPORT(*ALL)
CRTPGM PGM(MYMD5) BNDSRVPGM(MD5SRV)
Test
Open an editor and write
''Here is the Md5 Fingerprint'' on it and save on your dir

MD5 DATA('/home/sl/test.txt') TYPE(*STMF)
Fingerprint MD5:[b8:49:91:c5:ca:fb:93:86:ff:37:88:f7:c4:63:78:b1]

MD5 DATA('Here is the Md5 Fingerprint') TYPE(*STRING)
Fingerprint MD5:[b8:49:91:c5:ca:fb:93:86:ff:37:88:f7:c4:63:78:b1]

--
Stephane

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 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.