Thursday, January 14, 2016

AX2012/AX2009 X++ Base64 Convertion

The easiest method for me to get this working was to use the existing .net objects in X++

Conversion works as the following:

static void simpleBase64(Args _args)
{
    str val, valToConv;
    System.Byte[] bytes;
    System.Text.Encoding encoding = System.Text.Encoding::get_UTF8();
    ;
   
    valToConv = 'Hello World!';
    val = '';
   
    info(StrFmt('Vale to convert is : %1', valToConv));
   
    bytes = encoding.GetBytes(valToConv);
    val = System.Convert::ToBase64String(bytes);
   
    info(StrFmt('Value Converted to Base64: %1', val));
   
    bytes = System.Convert::FromBase64String(val);
    val = encoding.GetString(bytes);

    info(StrFmt('Value Converted back to String: %1', val));

}



No comments:

Post a Comment