midrange.com code scratchpad
Name:
code for updated program for decrypting data
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
11/11/2019 03:53:38 pm
IP:
Logged
Description:
when trying to call below program its giving call time error now like below,i have commented all callp except decrypt as i just want to test decryption part i have key and encoded data with me just want to test whether decryption works or not using this example.
Message ID . . . . . . : RNQ0202 Severity . . . . . . . : 99
Message type . . . . . : Inquiry
Date sent . . . . . . : 19-11-11 Time sent . . . . . . : 14:01:00

Message . . . . : The call to Qc3Decrypt ended in error (C G D F).
Cause . . . . . : RPG procedure AB1 in program RISHI/AB1 at statement 678
called program or procedure Qc3Decrypt, which ended in error. If the name is
*N, the call was a bound call by procedure pointer.
Recovery . . . : Check the job log for more information on the cause of the
error and contact the person responsible for program maintenance.
Possible choices for replying to message . . . . . . . . . . . . . . . :
D -- Obtain RPG formatted dump.
S -- Obtain system dump.
G -- Continue processing at *GETIN.
C -- Cancel.
F -- Obtain full formatted dump.
Bottom
Press Enter to continue.
Code:
  1.       * Sample RPG program: bill_cus
  2.       *
  3.       * COPYRIGHT 5722-SS1, 5761-SS1 (c) IBM Corp 2004, 2008
  4.       *
  5.       * This material contains programming source code for your
  6.       * consideration.  These examples have not been thoroughly
  7.       * tested under all conditions.  IBM, therefore, cannot
  8.       * guarantee or imply reliability, serviceability, or function
  9.       * of these programs.  All programs contained herein are
  10.       * provided to you "AS IS".  THE IMPLIED WARRANTIES OF
  11.       * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  12.       * EXPRESSLY DISCLAIMED.  IBM provides no program services for
  13.       * these programs and files.
  14.       *
  15.       * Description: This is a sample program to demonstrate use
  16.       * of the Cryptographic Services APIs.  APIs demonstrated in
  17.       * this program are:
  18.       *      Create Algorithm Context
  19.       *      Create Key Context
  20.       *      Decrypt Data
  21.       *      Destroy Key Context
  22.       *      Destroy Algorithm Context
  23.       *
  24.       * Function: For each record in the Customer Data file (CUSDTA),
  25.       * check the accounts receivable balance.  If there is a balance
  26.       * decrypt the customers data and call bill_cus to create a bill.
  27.       * The customer data is encrypted with a file key kept in the
  28.       * Customer Processing Information file (CUSPI).
  29.       *
  30.       * Refer to the IBM® i Information Center for a full
  31.       * description of this scenario.
  32.       *
  33.       * Use the following command to compile this program:
  34.       * CRTRPGMOD MODULE(MY_LIB/BILL_CUS) SRCFILE(MY_LIB/QRPGLESRC)
  35.       *
  36.      H bnddir('QC2LE')
  37.  
  38.      Fcuspi     uf   e             disk    usropn
  39.      Fcusdta    uf a e             disk    prefix(C) usropn
  40.  
  41.       * System includes
  42.      D/Copy QSYSINC/QRPGLESRC,QUSEC
  43.      D/Copy QSYSINC/QRPGLESRC,QC3CCI
  44.  
  45.       * Prototypes
  46.      DBill_Cus         pr            10i 0 extproc('Bill_Cus')
  47.  
  48.      DCreate_Bill      pr            10i 0 extproc('Create_Bill')
  49.      D cusDta                         1    const
  50.      D balance                       10  2 value
  51.  
  52.      DCrtAlgCtx        pr                  extproc('Qc3CreateAlgorithmContext')
  53.      D algD                           1    const
  54.      D algFormat                      8    const
  55.      D AESctx                         8
  56.      D errCod                         1
  57.  
  58.      DCrtKeyCtx        pr                  extproc('Qc3CreateKeyContext')
  59.      D key                            1    const
  60.      D keySize                       10i 0 const
  61.      D keyFormat                      1    const
  62.      D keyType                       10i 0 const
  63.      D keyForm                        1    const
  64.      D keyEncKey                      8    const options(*omit)
  65.      D keyEncAlg                      8    const options(*omit)
  66.      D keyTkn                         8
  67.      D errCod                         1
  68.  
  69.      DDestroyKeyCtx    pr                  extproc('Qc3DestroyKeyContext')
  70.      D keyTkn                         8    const
  71.      D errCod                         1
  72.  
  73.      DDestroyAlgCtx    pr                  extproc('Qc3DestroyAlgorithmContext')
  74.      D AESTkn                         8    const
  75.      D errCod                         1
  76.  
  77.      DDecryptData      pr                  extproc('Qc3DecryptData')
  78.      D encData                        1    const
  79.      D encDataSize                   10i 0 const
  80.      D algDesc                        1    const
  81.      D algDescFmt                     8    const
  82.      D keyDesc                        1    const
  83.      D keyDescFmt                     8    const
  84.      D csp                            1    const
  85.      D cspDevNam                     10    const options(*omit)
  86.      D clrDta                         1
  87.      D clrLenPrv                     10i 0 const
  88.      D clrLenRtn                     10i 0
  89.      D errCod                         1
  90.  
  91.      DPrint            pr            10i 0 extproc('printf')
  92.      D charString                     1    const options(*nopass)
  93.  
  94.      P*Bill_Cus         b                   export
  95.      D*Bill_Cus         pi            10i 0
  96.  
  97.       * Local variable
  98.      D csp             s              1    inz('0')
  99.      D error           s             10i 0 inz(-1)
  100.      D ok              s             10i 0 inz(0)
  101.      D rtn             s             10i 0
  102.      D rtnLen          s             10i 0
  103.      D plainLen        s             10i 0
  104.      D cipherLen       s             10i 0
  105.      D kekTkn          s              8
  106.      D AESctx          s              8
  107.      D KEKctx          s              8
  108.      D FKctx           s              8
  109.      D keySize         s             10i 0
  110.      D keyType         s             10i 0
  111.      D keyFormat       s              1
  112.      D keyForm         s              1
  113.      D inCusInfo       s             80
  114.      D inCusNum        s              8  0
  115.      D ECUSDTA         s             80
  116.  
  117.      C                   eval      QUSBPRV = 0
  118.       * Create an AES algorithm context for the key-encrypting key (KEK)
  119.      C                   eval      QC3D0200 = *loval
  120.      C                   eval      QC3BCA = 22
  121.      C                   eval      QC3BL = 16
  122.      C                   eval      QC3MODE = '1'
  123.      C                   eval      QC3PO = '0'
  124.      C*                  callp     CrtAlgCtx( QC3D0200 :'ALGD0200'
  125.      C*                                      :AESctx   :QUSEC)
  126.       * Create a key context for the key-encrypting key (KEK)
  127.      C                   eval      keySize = %size(QC3D040000)
  128.      C                   eval      keyFormat = '0'
  129.      C                   eval      keyType = 22
  130.      C                   eval      keyForm = '0'
  131.      C                   eval      QC3D040000 = *loval
  132.      C                   eval      QC3KS00 = 'CUSKEYFILEMY_LIB'
  133.      C                   eval      QC3RL = 'CUSDTAKEK'
  134.      C                   callp     CrtKeyCtx( QC3D040000 :keySize :'4'
  135.      C                                       :keyType    :keyForm :*OMIT
  136.      C                                       :*OMIT      :KEKctx  :QUSEC)
  137.      C
  138.       * Open CUSPI file
  139.      C                   open(e)   cuspi
  140.      C                   if        %error = '1'
  141.      C                   callp     Print('Open of Customer Processing -
  142.      C                                    Information File (CUSPI) failed')
  143.      C                   return
  144.      C                   endif
  145.       * Read first (only) record to get encrypted file key
  146.      C                   read(e)   cuspirec
  147.      C                   if        %eof = '1'
  148.      C                   callp     Print('Customer Processing Information -
  149.      C                                    (CUSPI) record missing')
  150.      C                   close     cuspi
  151.      C                   return
  152.      C                   endif
  153.      C                   close     cuspi
  154.       * Create a key context for the file key
  155.      C                   eval      keySize = %size(KEY)
  156.      C                   eval      keyFormat = '0'
  157.      C                   eval      keyType = 22
  158.      C                   eval      keyForm = '1'
  159.      C*                  callp     CrtKeyCtx( KEY     :keySize  :keyFormat
  160.      C*                                      :keyType :keyForm  :KEKctx
  161.      C*                                      :AESctx  :FKctx    :QUSEC)
  162.       * Wipe out the encrypted file key value from program storage
  163.      C                   eval      Key = *loval
  164.       * Open CUSDTA
  165.      C                   open(e)   cusdta
  166.      C                   if        %error = '1'
  167.      C                   callp     Print('Open of CUSDTA file failed')
  168.      C                   close     cuspi
  169.      C                   return
  170.      C                   endif
  171.       * Read each record of CUSDTA
  172.      C                   read(e)   cusdtarec
  173.      C                   dow       %eof <> '1'
  174.       * If accounts receivable balance > 0, decrypt customer data and
  175.       * create a bill
  176.      C                   if        CARBAL > 0
  177.       * Decrypt customer information
  178.      C                   eval      QC3IV = CIV
  179.      C                   eval      plainLen = %size(CCUSDTA)
  180.      C                   eval      cipherLen = %size(ECUSDTA)
  181.      C                   callp     DecryptData( CCUSDTA    :cipherLen
  182.      C                                         :QC3D0200   :'ALGD0200'
  183.      C                                         :FKctx      :'KEYD0100'
  184.      C                                         :csp        :*OMIT
  185.      C                                         :ECUSDTA    :plainLen
  186.      C                                         :rtnLen     :QUSEC)
  187.      C*                  callp     Create_Bill( ECUSDTA :CARBAL)
  188.      C                   endif
  189.      C                   read(e)   cusdtarec
  190.      C                   enddo
  191.       * Cleanup
  192.      C                   eval      ecusdta = *loval
  193.      C*                  callp     DestroyKeyCtx( FKctx  :QUSEC)
  194.      C*                  callp     DestroyKeyCtx( KEKctx :QUSEC)
  195.      C*                  callp     DestroyAlgCtx( AESctx  :QUSEC)
  196.      C                   close     cusdta
  197.      c                   return
  198.  
  199.      P*                 e
  200. ||||||||||||||
© 2004-2019 by midrange.com generated in 0.008s valid xhtml & css