0 Replies Latest reply on Nov 29, 2007 3:56 PM by eyewell

    Base64 encoding, then decoding, yields extra characters

    eyewell
      Issue:
      I am getting strange extra characters when I decode text that i have encoded

      Background:
      I have a procedure that does the following:
      *retrieves a base64 encoded file
      *decodes the file into text
      *displays the text in a Flex Textarea,
      *The user edits the text,
      *OnSave, the text is re-encoded in Base64,
      *then saved back to my database.

      I am using the Base64 encode and decode functions from the following ActionScript librairies
      mx.utils.Base64Decoder;
      mx.utils.Base64Encoder;

      Detail of the problem:
      When I go to re-edit the file that I had viewed and saved, I see a couple extra characters at the beginning of my file. The characters often look like "-g-h".
      I am not able to just trim the string, since it doesn't seem to always be 1 character long.

      Is this a bug or user error?
      Any recommendations, whether they be troubleshooting, or how to fix this?

      My Decode code is here:
      var b:Base64Decoder = new Base64Decoder();
      if (dHTMLDocument.Body != null)
      {
      b.decode(dHTMLDocument.Body);

      // display the decoded text on the screen
      var bytes:ByteArray = b.flush();
      tEditArea.text = bytes.toString();
      }

      and my Encode code is here:

      var bytes:ByteArray = new ByteArray();
      var sTemp:String = tEditArea.text;
      bytes.writeObject(tEditArea.text);
      bytes.position = 0;

      // encode the body of the document
      var b:Base64Encoder = new Base64Encoder();
      b.encode(bytes.readUTFBytes(bytes.length));

      // store any changes the user made to the document in memory
      sTemp = b.flush();
      dHTMLDocument.Body = sTemp;




      Thanks!
      Erik