MIME / Base64 problem.

Giganews Newsgroups
Subject: MIME / Base64 problem.
Posted by:  Terry Yapt (ya…@NOtechSPAMnovell.com)
Date: Sat, 10 Apr 2010

Delphi 2010 (up to date).

Hello,

I am trying to encode/decode an string from/to Base64 (mime)

I have this:

//==========================================================
uses
  IdCoderMIME;

const
  C_ENCODING    = 28591;
//==========================================================
function EncodeBase64(const AOrigen: String):string;
var
  b64 : TIdEncoderMIME;
begin
  result := 'Error EncBase 64';
  b64 := TIdEncoderMIME.Create;
  iso88591 := TEncoding.GetEncoding(C_ENCODING);
  try
    result := b64.EncodeString(AOrigen, iso88591);
  finally
    FreeAndNil(iso88591);
    FreeAndNil(b64);
  end;
end;
//==========================================================
function DecodeBase64(const AOrigen: String):string;
var
  b64 : TIdDecoderMIME;
begin
  result := 'Error DecBase 64';
  b64 := TIdDecoderMIME.Create;
  try
    result := b64.DecodeString(AOrigen);
  finally
    FreeAndNil(b64);
  end;
end;
//==========================================================
procedure TForm1.Button1Click(Sender: TObject);
begin
  edit2.Text    := EncodeBase64(edit1.text);
end;
//==========================================================
procedure TForm1.Button2Click(Sender: TObject);
begin
  edit1.Text    := DecodeBase64(edit2.Text);
end;
//==========================================================

Trying to encode this string (I hope this arrive as I has wrote):
êìê’äÑßÜÅçÔãÓÚ¢ÕâÒçê

I get this B64:
6uzqJ+TR39zF59Tj09qi1eLS5+o=

But when I try to decode, I get this:
êìê'äÑßÜÅçÔãÓÚ¢ÕâÒçê

Look at the 4th character because it is different...

Any idea ?

--

Replies