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:
- FUNIX IF F 1000 SPECIAL PGMNAME('UNIXCMD')
- F PLIST(UNIXPARM) USROPN
- FK1 IF E DISK
- 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
- Dreplkey s 100a inz
-
- C UNIXPARM PLIST
- C PARM CMD
- C PARM MODE
- /free
- RECORD = *BLANKS;
- OUTREC = *BLANKS;
- // replkey = '363631653237354f494d31554c594c4a';
- XML-INTO encodedExchangeToken %XML('/home/I0RS01HU/+
- IN2.xml':'doc=file case=any path=+
- TokenExchangeResponse/encodedExchangeToken');
- eval encodedExchangeToken =%trimr(encodedExchangeToken);
- read rec ;
- cmd = 'echo ' + '''' + encodedExchangeToken + ''' ! openssl +
- // enc -d -aes-128-ecb -K 363631653237354f494d31554c594c4a +
- enc -d -aes-128-ecb -K ' + %trimr(key) +
- ' -nopad -nosalt -base64 -A';
- open UNIX;
- read UNIX record;
- dow not %eof(UNIX);
- pos2 = %scan(x'10' :record);
- Record = %subst(Record :1 :(Pos2 - 1));
- 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(' + %char(N1) + ')';
- 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;
- return;
- /end-free
-
|
|
|