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:
- FUNIX IF F 1000 SPECIAL PGMNAME('UNIXCMD')
- F PLIST(UNIXPARM) USROPN
- F*QSYSPRT O F 1000 PRINTER
- dencodedExcha...
- dngeToken s 500 VARYING
-
- DPOS2 S 5U 0
- D cmd s 5000a
- D mode s 1A inz('P')
- DN1 S 2P 0
- D Åcommand s 512a
- d QCMDEXC PR ExtPgm('QCMDEXC')
- d command 500a const
- d clength 15p 5 const
-
- D record ds 1000
- D outrec s 1000 varying inz
-
- C UNIXPARM PLIST
- C PARM CMD
- C PARM MODE
- /free
- RECORD = *BLANKS;
- OUTREC = *BLANKS;
- XML-INTO encodedExchangeToken %XML('/home/I0RS01HU/+
- INPUT.xml':'doc=file case=any path=+
- TokenExchangeResponse/encodedExchangeToken');
- eval encodedExchangeToken =%trimr(encodedExchangeToken);
- cmd = 'echo ' + '''' + encodedExchangeToken + ''' ! openssl +
- enc -d -aes-128-ecb -K 363631653237354f494d31554c594c4a +
- -nopad -nosalt -base64 -A';
- open UNIX;
- read UNIX record;
- dow not %eof(UNIX);
- eval record = %trimr(%subst(record :1 :64) : x'10');
- eval outrec = %trimr(record);
- EVAL N1 = %LEN(OUTREC);
- DSPLY N1;
- //Delete the TESTFILE
- Åcommand = 'DLTF FILE(rishi/TESTFILE)';
- QCMDEXC(%trim(Åcommand): %len(%trim(Åcommand)));
- Åcommand = *blanks;
- Åcommand = 'CRTPF FILE(RISHI/TESTFILE) RCDLEN(500)';
- QCMDEXC(%trim(Åcommand): %len(%trim(Åcommand)));
- //Write into file
- EXEC SQL
- INSERT INTO rishi/TESTFILE VALUES (:outrec);
- // dsply %subst(outrec:1:48);
- read UNIX record;
- enddo;
- close UNIX;
- *inlr = *on;
- /end-free
-
|
|
|