我拼凑了这个小程序来使用 Indy 组件 (v10) 来解码一些 base-64 编码信息。我选择了TBytes 返回类型,因为 base-64 编码可用于任何“八位字节”序列。我认为最好不要返回字符串,因为这意味着文本已被编码。我们可以轻松地从字节数组中返回一个字符串。
除了TB的我使用的是相对较新的 TBytesStream流类,所以你需要如果使用旧DELPHIS做出一些改变。
function Base64Decode(const EncodedText: string): TBytes;
var
DecodedStm: TBytesStream;
Decoder: TIdDecoderMIME;
begin
Decoder := TIdDecoderMIME.Create(nil);
try
DecodedStm := TBytesStream.Create;
try
Decoder.DecodeBegin(DecodedStm);
Decoder.Decode(EncodedText);
Decoder.DecodeEnd;
Result := DecodedStm.Bytes;
finally
DecodedStm.Free;
end;
finally
Decoder.Free;
end;
end;
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.050518035888672 seconds