midrange.com code scratchpad
Name:
Decryption of encodedtokenexchange using OPENSSL AES128 Algorithm in RPGLE Program
Scriptlanguage:
Plain Text
Tabwidth:
5
Date:
11/01/2019 07:09:28 pm
IP:
Logged
Description:
Hi,
I am pasting below code which works pretty well for the interactive part of OPENSSL I mean when i execute call qsys/qp2term and then execute openssl and execute this command :-echo 'u3VtNgfyWU9faZc3Iaa8ZWbE5UZCfmC17yA4MyW0ghflt9dNQNDpCcgMZiG/kXPE4vv2CHL
93B4iKiODHxxdVA==' | openssl enc -d -aes-128-ecb -K 363631653237354f494d31554
c594c4a -nopad -nosalt -base64 -A

then i get decrypted value of this encoded string as :- 707fbe32-0dbc-41e0-888f-5bc40de8c20d2P9AMPCTQ4CZ ยข

and when same thing programatically i am willing to achieve using openssl and reading xml file's encodedtokenexchange field value from it and then trying to decrypt it using below program code it is not writing any thing in string1.txt and gives me error like :-
Display Module Source

Program: EX9 Library: RISHI Module: EX9
15 /free
16 XML-INTO encodedExchangeToken %XML('/home/I0RS01HU/+
17 /INPUT.xml':'doc=file case=any path=+
18 TokenExchangeResponse/encodedExchangeToken');
19 cmd = 'echo encodedExchangeToken|openssl +
20 enc -d -aes-128-ecb -K +
21 363631653237354f494d31554c594c4a -nopad -nosalt +
22 -base64 -A -out string1.txt';
23 read UNIX record;
24 dow not %eof(UNIX);
25 outrec = record;
26 write QSYSPRT outrec;
27 read UNIX record;
28 enddo;
29
More...
Debug . . . EVAL string1.txt

F3=End program F6=Add/Clear breakpoint F10=Step F11=Display variable
F12=Resume F17=Watch variable F18=Work with watch F24=More keys
Identifier does not exist.

Please find my program code pasted below for more details and could you please advise what is going wrong here?
Code:
  1.      FUNIX      IF   F 1000        SPECIAL PGMNAME('UNIXCMD')
  2.      F                                     PLIST(UNIXPARM)
  3.      FQSYSPRT   O    F  132        PRINTER
  4.      dencodedExcha...
  5.      dngeToken         s             88
  6.      DSTRING1          S            100
  7.      D cmd             s           5000a
  8.      D mode            s              1A   inz('P')
  9.      D record          ds          1000
  10.      D outrec          ds           132
  11.  
  12.      C     UNIXPARM      PLIST
  13.      C                   PARM                    CMD
  14.      C                   PARM                    MODE
  15.       /free
  16.        XML-INTO encodedExchangeToken %XML('/home/I0RS01HU/+
  17.        /INPUT.xml':'doc=file case=any path=+
  18.        TokenExchangeResponse/encodedExchangeToken');
  19.           cmd = 'echo encodedExchangeToken!openssl +
  20.           enc -d -aes-128-ecb -K +
  21.           363631653237354f494d31554c594c4a -nopad -nosalt +
  22.           -base64 -A -out string1.txt';
  23.           read UNIX record;
  24.           dow not %eof(UNIX);
  25.              outrec = record;
  26.              write QSYSPRT outrec;
  27.              read UNIX record;
  28.           enddo;
  29.  
  30.           close UNIX;
  31.           *inlr = *on;
  32.       /end-free
  33.  
© 2004-2019 by midrange.com generated in 0.007s valid xhtml & css