Introduction
The RFC-2822 standard specifies a syntax for text messages that are sent between computer users, within the framework of “electronic mail” messages. The RFC-2822 specifies lines should be no longer than 78 characters, and the MIME spec RFC-2045, says:
The encoded output stream must be represented in lines of no more than 76 characters each. All line breaks or other characters not found in Table 1- The Base64 Alphabet must be ignored by decoding software.
RAD Studio and TNetEncoding.Base64.
For example, given this Delphi code:
procedure TForm55.Button1Click(Sender: TObject);
var
S: string;
begin
S := ‘jfdlksjflkasjdlfow7r89fpsduf87s8fy4387rhfofldsajfhasddlsihjsldhjlsdhlfhjsdafhjsadh’;
Memo1.Text := TNetEncoding.Base64.EncodeBytesToString(TEncoding.GetEncoding(‘ISO-8859-1’).GetBytes(S));
end;
var
S: string;
begin
S := ‘jfdlksjflkasjdlfow7r89fpsduf87s8fy4387rhfofldsajfhasddlsihjsldhjlsdhlfhjsdafhjsadh’;
Memo1.Text := TNetEncoding.Base64.EncodeBytesToString(TEncoding.GetEncoding(‘ISO-8859-1’).GetBytes(S));
end;
You will notice that this produces a #13#10 in the middle.
Delphi and/or C++ Builder is automatically wrapping at 76 characters per line (TBase64Encoding.kCharsPerLine.) You can override this in one of the constructors and pass 0: TBase64Encoding.Create(0) where 0 means don’t wrap lines.
Delphi and C++ Builder does this because it’s a net encoding and base64 is used for representing binary in, eg, email; Recalling that the RFC-2822 specifies lines should be no longer than 78 characters and the MIME spec RFC-2045, and it says: “The encoded output stream must be represented in lines of no more than 76 characters each. All line breaks or other characters not found in Table 1- The Base64 Alphabet must be ignored by decoding software.”
We see that Delphi and C++ Builder matches the spec accurately!
This is completely valid. RAD Studio (Delphi and/or C++ Builder) creates 100% valid MIME base64 encoded text!
Compared to this corresponding .NET code, which (unlike Delphi or C++ Builder) does not put anything in the middle:
Convert.ToBase64String(Encoding.GetEncoding(“ISO-8859-1”).GetBytes(Key1+ “:” + Secret1))
[DownloadButton Product=’RAD’ Caption=’Start Your RAD Studio FREE Trial Today’]
Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition