× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Thanks Scott.
Since my initial variable value is in EBCDIC, this is what I am planning to
do:
1. Convert the variable to ASCII
2. Encode the ASCII value in BASE64
3. Convert the encoded value to EBCDIC and save back in my variable
4. Create JSON using DATA-GEN
5. Convert the JSON document to ASCII and send it out.

I am not encoding the complete JSON document in BASE64, as the consumer of
my data is expecting only that one variable to be encoded.

I was trying to write a test program to try the encoding, but it won't
Bind, giving error "apr_base64_encode" not found.

I tried adding library QSYSDIR to the LIBL, but got the same error message.
DSPSRVPGM for QSYSDIR/QAXIS10HT shows the procedure. Not sure what
the problem is.

Vinay

On Tue, Aug 8, 2023 at 7:26 PM Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx>
wrote:

Base64 always preserves the binary value of the data. That's what it's
all about. So if you want the data to be decoded in (which is weird for
an application newer that 1998 -- ASCII has mostly been replaced with
unicode.)

Your steps will look like this:

1) Get the ASCII data (in ASCII format) and encode it in base64.

2) Put the encoded data in your JSON field. If the JSON building tool
you're using is expecting input in EBCDIC, make sure you've converted
the base64-encoded string to EBCDIC (it won't change the underlying
values once decoded.)

3) Create your JSON document (which should be encoded in UTF-8 --a
version of Unicode -- that's the standard for JSON -- which means your
encoded string will also be encoded in UTF-8... again, it won't change
the underlying value.)

4) Encode the JSON document in base64 as well.

5) Send the result whereever it needs to go.

As for IBM-supplied APIs. They provide the Apache Portable Runtime
(APR) which has base64 routines, I'm not a huge fan, but they exist.
SQL also has a base64 function, that works nicely, aside from the fact
that it has a relatively short string length, which can be an issue
sometimes.

For creating JSON, I would either use SQL or DATA-GEN. Personally, I
prefer the latter -- I find it easier and more elegant, other people
prefer SQL... both will do the job.

-SK

On 8/8/2023 6:05 PM, Vinay Gavankar wrote:
Hi,

I want to create a JSON string where one of the fields needs to be BASE64
encoded. The JSON string will then be converted to ASCII to be sent out
to
be used by an ASCII based server.
For example,
{
"Field1" : "aaa",
"Field2" : "bbb",
"Field3" : "ccc"
}
where Value bbb needs to be BASE64 encoded.
I am assuming that BASE64 encoding of EBCDIC and ASCII will give
different
results, and just encoding bbb in EBCDIC before creating JSON string and
then converting full string to ASCII will not do the trick. Is that
correct?
Also, what is the best way of BASE64 encoding/decoding using IBM supplied
APIs?

Any ideas will be greatly appreciated. TIA
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxxxxxxxxxx for any subscription related
questions.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.