RPGLE generate SHA-1 Hash – Use Qc3CalculateHash, QDCXLATE to Hash MD5 SHA1 SHA256 SHA384 SHA512

In cryptography, SHA-1 is a cryptographic hash role designed past times the National Security Agency as well as published past times the NIST every bit a U.S. Federal Information Processing Standard. SHA stands for Secure Hash Algorithm. SHA-1 is the close widely used of the existing SHA hash functions, as well as is employed inward several widely-used safety applications as well as protocols.

SHA-1 produces a 160-bit message digest based on principles similar to those used past times Ronald L. Rivest of MIT inward the pattern of the MD4 as well as MD5 message digest algorithms, simply has a to a greater extent than conservative design.

Example SHA-1 hashes

These are examples of SHA-1 digests. ASCII encoding is used for all messages.

SHA1(“The quick chocolate-brown describe a fast 1 on jumps over the lazy dog”)
= 2fd4e1c6 7a2d28fc ed849ee1 bb76e739 1b93eb12

The hash of the zero-length string is:
SHA1(“”) = da39a3ee 5e6b4b0d 3255bfef 95601890 afd80709

RPGLE Sample Code to Generate SHA-1 Hash

You tin forcefulness out likewise utilization it to HASH MD5, SHA256, SHA384, SHA512

h DFTACTGRP(*NO) ACTGRP('AS') BNDDIR('QC2LE') debug                                                                                             d Qc3CalculateHash...                                                      d                 PR                  ExtProc('Qc3CalculateHash')          d   InData                        *   value                                d   IndataL                     10i 0 const                                d   InDataF                      8a   const                                d   AlgoDes                     16a   const                                d   AlgoFmt                      8a   const                                d   CryptoSP                     1a   const                                d   CryptoDev                    1a   const options(*omit)                 d   Hash                        64a   options(*varsize:*omit)              d   ErrorCode                32767a   options(*varsize)                                                                                               d ALGD0500_t      ds                  qualified                            d                                     based(Template)                      d   HashAlg                     10i 0                                                                                                                 d QDCXLATE        PR                  ExtPgm('QDCXLATE')                   d   len                          5p 0 const                                d   information                     32702a   options(*varsize)          d   tabular array                       10a   const                                                                                       d cvthc           PR                  ExtProc('cvthc')           d   target                   65534A   options(*varsize)          d   src_bits                 32767A   options(*varsize) const    d   tgt_length                  10I 0 value                                                                                       d ErrorNull       ds                  qualified                  d    BytesPro                   10i 0 inz(0)                     d    BytesAvai                  10i 0 inz(0)                       d HASH_MD5        c                   1 d HASH_SHA1       c                   ii d HASH_SHA256     c                   three d HASH_SHA384     c                   iv d HASH_SHA512     c                   v   d information            s           2000A                              d len             s             10i 0                            d alg             ds                  likeds(ALGD0500_t)         d bin             s             20a  d $hex            s             40a    /free                                                                                            len = %len(%trimr(data));                     alg.HashAlg = HASH_SHA1;     //Set the HASH Algorithm you lot desire to utilization !             //Convert from EBCDIC to ASCII (skip this pace if you lot desire Hash inward EBCDIC)                QDCXLATE(len: data: 'QTCPASC');     //API to calculate the SHA1 hash       Qc3CalculateHash( %addr(data)                                 : len                                         : 'DATA0100'                                  : alg                                         : 'ALGD0500'                                  : '0'                                         : *OMIT                                       : bin                                         : ErrorNull );                                                              //Convert to HEX                                             cvthc( $hex: bin: %len(bin)*2);    dsply $hex;        *inlr = *on;                                                                           /end-free             

This programme uses the Qc3CalculateHash API to calculate the SHA1 hash. It as well as thence uses the cvthc() MI role to exercise a hex representation of the hash to display on the screen. The QDCXLATE API is used to convert the hash from EBCDIC to ASCII.

Sumber http://www.mysamplecode.com/