[DUG] Brain explosion ! (mime64)

Jolyon Smith jsmith at deltics.co.nz
Tue Aug 25 15:15:24 NZST 2009


I would say there doesn't appear to be anything wrong with that code, so my
next question would be what are these Base64xxx functions and are you
certain that they are working correctly?

Or perhaps show us the code you use to write the Base64Encode'd result to
the file that your decode code then determines is invalid?


Possible places where the error might occur:

  - writing of the encoded data to the file
  - reading of the encoded data FROM that file, prior to decoding
  - bug(s) in the Base64 encode/decode functions themselves


If you are using a stringlist to save the output as you say you are, then I
suspect that may be where your error is creeping in.... a stringlist will
expect to be dealing with, well, a list of strings, and may respond to
characters in the base64 encoded data inappropriately for your needs.

Why not simply use a file stream to save the encoded result?


-----Original Message-----
From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Robert martin
Sent: Tuesday, 25 August 2009 14:33
To: NZ Borland Developers Group - Delphi List
Subject: [DUG] Brain explosion ! (mime64)

Hi

I have a set of functions (not written by me) that encode and decode 
mime64 data.  I want to take a file and mime64 encrypt it than at a 
later point decrypt it.  However I am having trouble calling the 
functions and there is no help.

Functions

function Base64Encode(const InText: string): string; overload;

function Base64Decode(const InText: string): string; overload;


To do the encode I have the following function

var
    fs          : TFileStream;
    BufferIn    : AnsiString;
begin
    fs := TFileStream.Create(FileName, fmOpenRead);
    try
        fs.Position := 0;

        SetString(BufferIn, nil, fs.Size);
        fs.Read(Pointer(BufferIn)^, fs.Size);
        Result := Base64Encode(BufferIn);
    finally
        fs.Free;
    end;


I use a string list to save the output.  I thought this was working but 
when I come to decode it the system checks and finds it is an invalid 
file (does not divide evenly by 4).  Can anyone see what might be wrong 
with the above?

Cheers
Rob

_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe



More information about the Delphi mailing list