midrange.com code scratchpad
Name:
spool file and updated program example code
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
11/10/2019 06:29:41 pm
IP:
Logged
Description:
below is the spool file and program code.
Code:
  1.      h        bnddir ('QC2LE')
  2.      FCUSPI     UF   E             DISK    USROPN
  3.      FCUSDTA    UF A E             DISK    PREFIX(C) USROPN
  4.      D/COPY QSYSINC/QRPGLESRC,QUSEC
  5.      D/COPY QSYSINC/QRPGLESRC,QC3CCI
  6.      DBILL_CUS         Pr            10I 0 EXTPROC('Bill_Cus')
  7.      d create_bill     pr            10i 0 extproc('create_bill')
  8.      d cusdta                         1    const
  9.      d balance                       10  2 value
  10.      dcrtalgctx        pr                  extproc('Qc3CreateAlgorithmContext')
  11.      dalgd                            1    const
  12.      dalgFormat                       8    const
  13.      dAESctx                          8
  14.      derrCod                          1
  15.      dCrtKeyCtx        PR                  extproc('Qc3CreateKeyContext')
  16. rishiDKEY                             1    CONST
  17.      DKEYSIZE                        10I 0 CONST
  18.      DKEYFORMAT                       1    CONST
  19.      DKEYTYPE                        10I 0 CONST
  20.      DKEYFORM                         1    CONST
  21.      DKEYENCKEY                       8    CONST  OPTIONS(*OMIT)
  22.      DKEYENCALG                       8    CONST  OPTIONS(*OMIT)
  23.      DKEYTKN                          8
  24.      DERRCOD                          1
  25.      DDESTROYKEYCTX    PR                  EXTPROC ('Qc3DestroyKeyContext')
  26.      DKEYTKN                          8    CONST
  27.      DERRCOD                          1
  28.      DDestroyAlgCtx    PR                  EXTPROC('Qc3DestroyAlgorithmCont+
  29.      D                                             ext')
  30.      dAESTkn                          8    CONST
  31.      Derrcod                          1
  32.      dDecryptData      pr                  extproc('Qc3DecryptData')
  33.      Dencdata                         1    const
  34.      D encDataSize                   10i 0 const
  35.      D algDesc                        1    const
  36.      D algDescFmt                     8    const
  37.      D keyDesc                        1    const
  38.      D keyDescFmt                     8    const
  39.      D csp                            1    const
  40.      D cspDevNam                     10    const options(*omit)
  41.      D clrDta                         1
  42.      D clrLenPrv                     10i 0 const
  43.      D clrLenRtn                     10i 0
  44.      D errCod                         1
  45.  
  46.      DPrint            pr            10i 0 extproc('printf')
  47.      D charString                     1    const options(*nopass)
  48.      PBill_Cus         b                   export
  49.      DBill_Cus         pi            10i 0
  50.      D csp             s              1    inz('0')
  51.      D error           s             10i 0 inz(-1)
  52.      D ok              s             10i 0 inz(0)
  53.      D rtn             s             10i 0
  54.      D rtnLen          s             10i 0
  55.      D plainLen        s             10i 0
  56.      D cipherLen       s             10i 0
  57.      D kekTkn          s              8
  58.      D AESctx          s              8
  59.      D KEKctx          s              8
  60.      D FKctx           s              8
  61.      D keySize         s             10i 0
  62.      D keyType         s             10i 0
  63.      D keyFormat       s              1
  64.      D keyForm         s              1
  65.      D inCusInfo       s             80
  66.      D inCusNum        s              8  0
  67.      D ECUSDTA         s             80
  68.      C                   eval      QUSBPRV = 0
  69.       *    * Create an AES algorithm context for the key-encrypting key
  70.       *    *(KEK)
  71.      C                   eval      QC3D0200 = *loval
  72.      C                   eval      QC3BCA = 22
  73.      C                   eval      QC3BL = 16
  74.      C                   eval      QC3MODE = '1'
  75.      C                   eval      QC3PO = '0'
  76.      C                   callp     CrtAlgCtx( QC3D0200 :'ALGD0200'
  77.      C                                       :AESctx   :QUSEC)
  78.       * Create a key context for the key-encrypting key (KEK)
  79.      C                   eval      keySize = %size(QC3D040000)
  80.      C                   eval      keyFormat = '0'
  81.      C                   eval      keyType = 22
  82.      C                   eval      keyForm = '0'
  83.      C                   eval      QC3D040000 = *loval
  84.      C                   eval      QC3KS00 = 'CUSKEYFILEMY_LIB'
  85.      C                   eval      QC3RL = 'CUSDTAKEK'
  86.      C                   callp     CrtKeyCtx( QC3D040000 :keySize :'4'
  87.      C                                       :keyType    :keyForm :*omit
  88.      c                                       :*omit    :kekctx    :QUSEC)
  89.       * Open CUSPI file
  90.      C                   open(e)   cuspi
  91.      C                   if        %error = '1'
  92.      C                   callp     Print('Open of Customer Processing -
  93.      C                                    Information File (CUSPI) failed')
  94.      C                   return    error
  95.      C                   endif
  96.      c*Read first (only) record to get encrypted file key
  97.      C                   read(e)   cuspirec
  98.      C                   if        %eof = '1'
  99.      C                   callp     Print('Customer Processing information cuspi-
  100.      C                             record missing')
  101.      C                   close     cuspi
  102.      c                   return    error
  103.      C                   endif
  104.      C                   close     cuspi
  105.      C*    * Create a key context for the file key
  106.      C                   eval      keySize = %size(KEY)
  107.      C                   eval      keyFormat = '0'
  108.      C                   eval      keyType = 22
  109.      C                   eval      keyForm = '1'
  110.      C                   callp     CrtKeyCtx( KEY     :keySize   :keyFormat
  111.      c                             :keytype :keyform  :KEKctx
  112.      c                             :AESctx  :FKctx    :QUSEC)
  113.      c*Wipe out the encrypted file key value from program storage
  114.      C                   eval      Key = *loval
  115.       *  Open CUSDTA
  116.      C                   open(e)   cusdta
  117.      C                   if        %error = '1'
  118.      C                   callp     Print('Open of CUSDTA file failed')
  119.      c                   close     cuspi
  120.      c                   return    error
  121.      c                   endif
  122.       * read each record of CUSDTA
  123.      C                   READ(E)   CUSDTAREC
  124.      C                   DOW       %EOF <> '1'
  125.      C*If accounts receivable balance > 0, decrypt customer data and
  126.       * create a bill
  127.      C                   if        CARBAL > 0
  128.       * Decrypt customer information
  129.      C                   eval      QC3IV = CIV
  130.      C                   eval      plainLen = %size(CCUSDTA)
  131.      C                   eval      cipherLen = %size(ECUSDTA)
  132.      C                   callp     DecryptData( CCUSDTA    :cipherLen
  133.      C                                         :QC3D0200   :'ALGD0200'
  134.      C                                         :FKctx      :'KEYD0100'
  135.      C                                         :csp        :*OMIT
  136.      C                                         :ECUSDTA    :plainLen
  137.      C                                         :rtnLen     :QUSEC)
  138.      C                   callp     Create_Bill( ECUSDTA :CARBAL)
  139.      C                   endif
  140.      C                   read(e)   cusdtarec
  141.      C                   enddo
  142.       * Cleanup
  143.      C                   eval      ecusdta = *loval
  144.      C                   callp     DestroyKeyCtx( FKctx  :QUSEC)
  145.      C                   callp     DestroyKeyCtx( KEKctx :QUSEC)
  146.      C                   callp     DestroyAlgCtx( AESctx  :QUSEC)
  147.      C                   close     cusdta
  148.      C                   return    ok
  149.  
  150.      c                   eval      *inlr = *on
  151.      P                 e
  152. *********************************************************************************************************
  153. errors after compilation of above code:-
  154.  
  155. 5770WDS V7R3M0  160422 RN        IBM ILE RPG             RISHI/DCR6           
  156.                          M e s s a g e   S u m m a r y                        
  157. Msg id  Sv Number Message text                                                
  158. RNF5409 00      4 The prototyped call returns a value which is lost when CALL 
  159.                   is used.                                                    
  160. RNF7031 00     98 The name or indicator is not referenced.                    
  161.       * * * * *   E N D   O F   M E S S A G E   S U M M A R Y   * * * * *     
  162.  
© 2004-2019 by midrange.com generated in 0.007s valid xhtml & css