Submitted by Anonymous (not verified) on Fri, 03/15/2013 - 00:00
Forums

Hi,

I'm trying to use base64encodestr() but am not getting the response I'm expecting.

If I use the string:

     "This is a base64 encoded string"

I would expect:

    VGhpcyBpcyBhIGJhc2U2NCBlbmNvZGVkIHN0cmluZw==

IceBreak gives something like:

    îåÇøÄ`âøÄ`âÇñå$ÇÄ í +äâ%Â_+Î!åî,ñç+ Ä_%Í!Ï

I've tried adding xlateStr( myStr : 0 : 1252 ) but this still does not help.

What am I missing?

Regards,
David

Niels Liisberg

Fri, 03/15/2013 - 00:00

Hi David,

No wonder you are in limbo!! The base64encodeStr always returns an ascii string. This is due to the implementation of the binary values in the base64 format which is always in ascii. So you need to convert the input to ascii and then result back to EBCDIC after you have decoded it.

In that case you will have the same base64String as if you did the conversion on a website like http://www.motobit.com/util/base64-decoder-encoder.asp presumably running 100% ASCII.

Your RPGcode has to look like:

<%@ language="RPGLE" %>
<%

var a like(string)
var s like(string)
var o like(string)
var e like(string)
var p like(string)

/free
  *inlr = *ON;
  s = 'This is a base64 encoded string';
  %><br><%= s %><br><%

  a = xlateStr(s:0:1252);
  o = Base64EncodeStr(a); // Base64 takes ASCII strings

  e = xlateStr(o:1252:0); // e is out EBCDIC version of o
  %><br><%= e %><br><%

  p = base64DecodeStr(o); // The decoder also takes ASCII strings
  e = xlateStr(p:1252:0); // e is out EBCDIC version of o
  %><br><%= e %><br><%

Best regards,
Niels Liisberg