midrange.com code scratchpad
Name:
Decryption of encodedtokenexchange using OPENSSL AES128 Algorithm in RPGLE Program
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
11/20/2019 03:08:14 pm
IP:
Logged
Description:
Hi,

Below code is working well and not writing any junk value in my test file but will also be able to handle some other enciodedexchangetoken s as well which might come from different XML files so based on those different encodedexchangetokens decrypted values will also vary but question is will below code be able to handle those junk values as well which are currently unknown to us.
Code:
  1.      FUNIX      IF   F 1000        SPECIAL PGMNAME('UNIXCMD')
  2.      F                                     PLIST(UNIXPARM) USROPN
  3.      F*QSYSPRT   O    F 1000        PRINTER
  4.      dencodedExcha...
  5.      dngeToken         s            500    VARYING
  6.  
  7.      DPOS2             S              5U 0
  8.      D cmd             s           5000a
  9.      D mode            s              1A   inz('P')
  10.      DN1               S              2P 0
  11.      D Åcommand        s            512a
  12.      d QCMDEXC         PR                  ExtPgm('QCMDEXC')
  13.      d   command                    500a   const
  14.      d   clength                     15p 5 const
  15.  
  16.      D record          ds          1000
  17.      D outrec          s           1000    varying  inz
  18.  
  19.      C     UNIXPARM      PLIST
  20.      C                   PARM                    CMD
  21.      C                   PARM                    MODE
  22.       /free
  23.        RECORD = *BLANKS;
  24.        OUTREC = *BLANKS;
  25.        XML-INTO encodedExchangeToken %XML('/home/I0RS01HU/+
  26.        INPUT.xml':'doc=file case=any path=+
  27.        TokenExchangeResponse/encodedExchangeToken');
  28.        eval encodedExchangeToken =%trimr(encodedExchangeToken);
  29.        cmd = 'echo ' + '''' +  encodedExchangeToken + ''' ! openssl +
  30.           enc -d -aes-128-ecb -K 363631653237354f494d31554c594c4a +
  31.           -nopad -nosalt -base64 -A';
  32.        open UNIX;
  33.        read UNIX record;
  34.        dow not %eof(UNIX);
  35.        eval record = %trimr(%subst(record :1 :64) : x'10');
  36.        eval outrec = %trimr(record);
  37.        EVAL N1  = %LEN(OUTREC);
  38.         DSPLY N1;
  39.         //Delete the TESTFILE
  40.           Åcommand = 'DLTF FILE(rishi/TESTFILE)';
  41.           QCMDEXC(%trim(Åcommand): %len(%trim(Åcommand)));
  42.           Åcommand = *blanks;
  43.           Åcommand = 'CRTPF FILE(RISHI/TESTFILE) RCDLEN(500)';
  44.           QCMDEXC(%trim(Åcommand): %len(%trim(Åcommand)));
  45.         //Write into file
  46.            EXEC SQL
  47.           INSERT INTO rishi/TESTFILE VALUES (:outrec);
  48.       //   dsply %subst(outrec:1:48);
  49.            read UNIX record;
  50.            enddo;
  51.         close UNIX;
  52.         *inlr = *on;
  53.       /end-free
  54.  
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css