sponsored links

Collapse

Announcement

Collapse
No announcement yet.

IBM Base64 API in RPG - apr_base64_decode procedure

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • IBM Base64 API in RPG - apr_base64_decode procedure

    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.

    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
    The Plain Text of my base 64 data is supposedly
    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   '                                                            '
    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.
    Attached Files

  • #2
    I think the base64 encoded input string is expected to be ascii and the rpg program is not supplying ascii data to the apr_base64_decode procedure. Try converting the base64data to ascii before calling the apr_base64_decode procedure.

    Comment


    • #3
      Is this the job of iconv api? DECDATA must be converted first into ascii?
      I wished IBM provided a working document for these procedures. I am only depending from discussion forums.


      Comment


      • #4
        I backtracked for a simple test of encoding 'AA' and decoding the resulting character.
        Code:
        0004.53        // encode                                                              
        0004.55        declen = apr_base64_encode(ENCODED:%trim(DECDATA):%len(DECDATA));      
        0004.56        dsply ENCODED;                                                         
        0004.57                                                                               
        0005.03        // decode                                                              
        0005.04        declen = apr_base64_decode(DECODED:%trim(ENCODED));                    
        0005.08                                                                               
        0005.09        dsply DECODED;
        apr_base64_encode is working OK and is producing "QUE=". Unfortunately, apr_base64_decode using the resulting value from encode, ends up with empty value. HELP please

        Comment


        • #5
          The procedures require ascii.

          Maybe something like this
          Code:
          d in              s          32764a   ccsid(819)  
          d out             s          32764a   ccsid(819)  
          
               in = 'AA';
               declen = apr_base64_encode(in:%trim(in):%len(in));
               declen = apr_base64_decode(out:%trim(in));

          Comment


          • #6
            Most likely 819 wouldn't be the right CCSID for the ASCII string. 819 is for the "Latin" character set which is used for the European languages including English. It doesn't include the Arabic characters. From this page, it looks like 864 would be the right CCSID. https://www.ibm.com/support/knowledg...fht8c0056.html

            Comment

            sponsored links

            Collapse

            Working...
            X