I am trying to use IBM supplied apr_base64_decode in RPG. But the decoded string is ending up as garabage.
Please help me identify what I am missing. Is this due to the Arabic (420) CCSID of our IBM i machine and I need to perform proper conversion? Hoping for guidance.
The Plain Text of my base 64 data is supposedly
I can see that the BASE64DATA was properly composed for DECDATA variable
But my DECODED is ending up as garbage
DECODED.png
I have tried similar code in Java using the Oracle/Sun supplied API and it is working fine (I did asked String to use UTF-8 when I instantiated it with the byte[] decoded data). It is even already reading from a CLOB field in DB2 400. Unfortunately, I have to do the work in RPG.
Please help me identify what I am missing. Is this due to the Arabic (420) CCSID of our IBM i machine and I need to perform proper conversion? Hoping for guidance.
Code:
0001.00 H BNDDIR('BASE64':'QC2LE') 0001.01 /copy APR_B64_H 0001.02 0001.03 D BASE64DATA s 70A DIM(3) CTDATA PERRCD(1) 0003.00 d decdata s 32764a 0003.01 d decoded s 32764a 0003.02 d declen s 10i 0 0003.03 d i s 10i 0 0004.00 /free 0004.01 // read the data in and concat it together 0004.02 for i = 1 to %elem(base64data); 0004.03 decdata = %trimr(decdata) + base64data(i); 0004.04 endfor; 0004.05 0004.06 // decode 0004.07 declen = apr_base64_decode(DECODED:DECDATA); 0004.08 0004.11 *inlr = *on; 0004.14 /end-free 0005.00 0006.00 ** BASE64DATA 0008.00 VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cgICAgeg0KQm 0009.00 FhIGJhYSBibGFjayBzaGVlcCBoYXZlIHlvdSBhbnkgd29vbCAgICAgICAgICAgeg0KSmFj 0010.00 ayBhbmQgSmlsbCB3ZW4gdXAgdGhlIGhpbGwgICAgICAgICAgICAgICAgICAgeg0K
Code:
The quick brown fox jumped over the lazy dog z Baa baa black sheep have you any wool z Jack and Jill wen up the hill z
I can see that the BASE64DATA was properly composed for DECDATA variable
Code:
EVAL DECDATA DECDATA = ....5...10...15...20...25...30...35...40...45...50...55...60 1 'VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cg' 61 'ICAgeg0KQmFhIGJhYSBibGFjayBzaGVlcCBoYXZlIHlvdSBhbnkgd29vbCAg' 121 'ICAgICAgICAgeg0KSmFjayBhbmQgSmlsbCB3ZW4gdXAgdGhlIGhpbGwgICAg' 181 'ICAgICAgICAgICAgICAgeg0K ' 241 ' '
DECODED.png
I have tried similar code in Java using the Oracle/Sun supplied API and it is working fine (I did asked String to use UTF-8 when I instantiated it with the byte[] decoded data). It is even already reading from a CLOB field in DB2 400. Unfortunately, I have to do the work in RPG.
Comment