1 Reply Latest reply on May 31, 2007 1:25 AM by Cédriic

    Base64 Encoding Problem

    Cédriic Level 1
      I have a String representation of an hexadecimal number such that :
      var s:String = "5300ca"; // 0x53, 0x00, 0xca

      I want to cut this string into 3 bytes (0x53, 0x00, 0xca) to use base64 encoding (3 x 8 bits returns 4 characters with base64 encoding). Here is my code :

      import mx.utils.*;
      import flash.utils.*;

      var byte1:int = parseInt("0x53");
      var byte2:int = parseInt("0x00");
      var byte3:int = parseInt("0xca");

      var b:ByteArray = new ByteArray();
      b.writeMultiByte(String.fromCharCode(byte1) + String.fromCharCode(byte2) + String.fromCharCode(byte3), "utf-16");

      var base64Encoder:Base64Encoder = new Base64Encoder();

      var result:String = base64Encoder.drain(); // result = "Uw=="

      The result string is "Uw==" whereas it should be "UwDK" according to the normalized base64-encoding !
      Is it a bug in the base-64 encoding ?