Scott Klement has one....
* MD5R4: Calculate the MD5 hash of a stream file in the IFS.
* Scott Klement, May 19, 2005
*
* To Compile:
* CRTBNDRPG MD5R4 SRCFILE(xxx/QRPGLESRC) DBGVIEW(*LIST)
* CRTCMD CMD(MD5) SRCFILE(xxx/QCMDSRC) PGM(xxx/MD5R4)
*
* Note: Because the first parameter to this program is larger
* than 32 bytes, you must call this through the MD5
* command interface.
*
H DFTACTGRP(*NO) BNDDIR('QC2LE')
/copy ifsio_h
D MD5R4 PR ExtPgm('MD5R4')
D StreamFile 5000A varying
D MD5R4 PI
D StreamFile 5000A varying
D ReportError PR
*
* _CIPHER MI builtin. Allows access to cryptographic
* functions in the licensed internal code.
*
D cipher PR extproc('_CIPHER')
D receiver * value
D control * value
D source * value
D HASH C const(5)
D MD5 C const(x'00')
D SHA1 C const(x'01')
D ONLY C const(x'00')
D FIRST C const(x'01')
D MIDDLE C const(x'02')
D FINAL C const(x'03')
*
* These control how the system creates a hash
*
D HashCtrl DS qualified
D Function 5I 0 inz(HASH)
D HashAlg 1A inz(x'00')
D Sequence 1A inz(x'00')
D Length 10I 0 inz
D Output 1A inz(x'00')
D Reserved 7A inz(x'00000000000000')
D CtxPtr * inz(%addr(WorkArea))
D WorkArea S 160A inz(*loval)
*
* MI builtin to create a hex dump of a spot in memory
*
D hexdump PR EXTPROC('cvthc')
D output 40A
D input 20A
D output_len 10I 0 value
D fsstats ds likeds(ds_statvfs)
D ReadBuf S *
D BufSize s 10I 0
D Len s 10I 0
D fd s 10I 0
D BinHash S 20A inz(*loval)
D HexHash s 40A
D p_BinHash s * inz(%addr(BinHash))
/free
*inlr = *on;
//
// Get file system statistics to find out the size of a
// disk block. IFS Disk access is fastest when you read
// an even multiple of these blocks.
//
if (statvfs( %trimr(StreamFile): fsstats ) = -1);
ReportError();
endif;
BufSize = fsstats.f_bsize * 8;
ReadBuf = %alloc(BufSize);
//
// Open the stream file for reading
//
fd = open( %trimr(StreamFile) : O_RDONLY );
if (fd < 0);
dealloc readbuf;
ReportError();
endif;
// Read stream file, calculate hash on each chunk
// of data.
len = read(fd: readBuf: bufSize);
hashCtrl.Sequence = FIRST;
dow (len > 0);
hashCtrl.Length = len;
cipher( %addr(p_BinHash)
: %addr(HashCtrl)
: %addr(ReadBuf) );
len = read(fd: readBuf: bufSize);
hashCtrl.Sequence = MIDDLE;
enddo;
// At the very end, call cipher with Sequence=FINAL
// to get back the MD5 hash
hashCtrl.Sequence = FINAL;
hashCtrl.Length = 0;
cipher( %addr(p_BinHash)
: %addr(HashCtrl)
: %addr(ReadBuf) );
dealloc readbuf;
callp close(fd);
// Apps that use MD5 hashes usually want them to be
// hexidecimal and lowercase. Here, that is done...
hexdump( HexHash : BinHash : %size(HexHash) );
HexHash = %xlate('ABCDEF': 'abcdef': HexHash);
dsply ('MD5 hash is ' + %subst(HexHash:1:32));
/end-free
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* ReportError(): Send an escape message explaining any errors
* that occurred.
*
* This function requires binding directory QC2LE in order
* to access the __errno() function.
*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
P ReportError B
D ReportError PI
D get_errno PR * ExtProc('__errno')
D ptrToErrno s *
D errno s 10I 0 based(ptrToErrno)
D QMHSNDPM PR ExtPgm('QMHSNDPM')
D MessageID 7A Const
D QualMsgF 20A Const
D MsgData 1A Const
D MsgDtaLen 10I 0 Const
D MsgType 10A Const
D CallStkEnt 10A Const
D CallStkCnt 10I 0 Const
D MessageKey 4A
D ErrorCode 8192A options(*varsize)
D ErrorCode DS qualified
D BytesProv 1 4I 0 inz(0)
D BytesAvail 5 8I 0 inz(0)
D MsgKey S 4A
D MsgID s 7A
/free
ptrToErrno = get_errno();
MsgID = 'CPE' + %char(errno);
QMHSNDPM( MsgID
: 'QCPFMSG *LIBL'
: ' '
: 0
: '*ESCAPE'
: '*PGMBDY'
: 1
: MsgKey
: ErrorCode );
/end-free
P E
On 12/19/18, 9:49 AM, "MIDRANGE-L on behalf of Versfelt, Charles" <midrange-l-bounces@xxxxxxxxxxxx on behalf of CVERSFELT@xxxxxxxxx> wrote:
There's an article in mcpress about creating md5 hash using rpg and sql.
https://www.mcpressonline.com/programming/rpg/create-an-md5-hash-using-rpg-and-sql
It was a great overview, but the RPG sample program was missing.
The word MD5R was supposed to link to a .zip file containing the sample program.
I click on the link and I get:
The requested URL /images/images/stories/ArticleCode/2011/030211Sanso_md5r.rpgle.zip was not found on this server.
Does anyone have the missing MD5R sample program that was supposed to be attached to the article?
Or, if not, some other sample code on creating MD5 hash?
I'm writing a hashing program for the first time.
Thanks,
Charles
This email message has been scanned for viruses and malware by Mimecast.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit:
https://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at
https://archive.midrange.com/midrange-l.
Please contact support@xxxxxxxxxxxx for any subscription related questions.
Help support midrange.com by shopping at amazon.com with our affiliate link:
https://amazon.midrange.com
As an Amazon Associate we earn from qualifying purchases.