midrange.com code scratchpad
Name:
converting key field in hex format
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
11/25/2019 04:48:23 pm
IP:
Logged
Description:
Hi,

I tried not to hardcode key field value instead of this i tried to read it's value from a file but the problem is it should not be in HEX format whereas i am reading HEX value of 'KEY ' (field name) only which i have inserted in k1 file(key-field ) in HEX Format but how can i programmatically convert this ascii value to hex value and then pass it to openssl in below program any suggestions on it please?

Thanks
Code:
  1.      FUNIX      IF   F 1000        SPECIAL PGMNAME('UNIXCMD')
  2.      F                                     PLIST(UNIXPARM) USROPN
  3.      FK1        IF   E             DISK
  4.      F*QSYSPRT   O    F 1000        PRINTER
  5.      dencodedExcha...
  6.      dngeToken         s            500    VARYING
  7.  
  8.      DPOS2             S              5U 0
  9.      D cmd             s           5000a
  10.      D mode            s              1A   inz('P')
  11.      DN1               S              2P 0
  12.      D Åcommand        s            512a
  13.      d QCMDEXC         PR                  ExtPgm('QCMDEXC')
  14.      d   command                    500a   const
  15.      d   clength                     15p 5 const
  16.  
  17.      D record          ds          1000
  18.      D outrec          s           1000    varying  inz
  19.      Dreplkey          s            100a   inz
  20.  
  21.      C     UNIXPARM      PLIST
  22.      C                   PARM                    CMD
  23.      C                   PARM                    MODE
  24.       /free
  25.        RECORD = *BLANKS;
  26.        OUTREC = *BLANKS;
  27.        // replkey = '363631653237354f494d31554c594c4a';
  28.        XML-INTO encodedExchangeToken %XML('/home/I0RS01HU/+
  29.        IN2.xml':'doc=file case=any path=+
  30.        TokenExchangeResponse/encodedExchangeToken');
  31.        eval encodedExchangeToken =%trimr(encodedExchangeToken);
  32.        read rec ;
  33.        cmd = 'echo ' + '''' +  encodedExchangeToken + ''' ! openssl +
  34.        // enc -d -aes-128-ecb -K 363631653237354f494d31554c594c4a +
  35.           enc -d -aes-128-ecb -K ' + %trimr(key) +
  36.           ' -nopad -nosalt -base64 -A';
  37.        open UNIX;
  38.        read UNIX record;
  39.        dow not %eof(UNIX);
  40.        pos2 = %scan(x'10' :record);
  41.        Record = %subst(Record :1 :(Pos2 - 1));
  42.        eval outrec = %trimr(record);
  43.        EVAL N1  = %LEN(OUTREC);
  44.         DSPLY N1;
  45.         //Delete the TESTFILE
  46.           Åcommand = 'DLTF FILE(rishi/TESTFILE)';
  47.           QCMDEXC(%trim(Åcommand): %len(%trim(Åcommand)));
  48.           Åcommand = *blanks;
  49.           Åcommand = 'CRTPF FILE(RISHI/TESTFILE) RCDLEN(' + %char(N1) + ')';
  50.           QCMDEXC(%trim(Åcommand): %len(%trim(Åcommand)));
  51.         //Write into file
  52.            EXEC SQL
  53.           INSERT INTO rishi/TESTFILE VALUES (:outrec);
  54.       //   dsply %subst(outrec:1:48);
  55.            read UNIX record;
  56.            enddo;
  57.         close UNIX;
  58.         return;
  59.       /end-free
  60.  
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css