![]() |
|
Decode Base64 into Memo or file - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Atozed Software (https://www.atozed.com/forums/forum-1.html) +--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html) +---- Forum: English (https://www.atozed.com/forums/forum-16.html) +----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html) +----- Thread: Decode Base64 into Memo or file (/thread-1072.html) Pages:
1
2
|
RE: Decode Base64 into Memo or file - rlebeau - 06-25-2019 (06-25-2019, 03:06 PM)staff@ergosoft.it Wrote: sorry but I have some problems with the suggestions indicated above ... Why are you using AnsiString for everything? You originally tried TNetEncoding, which was first added in Delphi XE7, so you are clearly using a Unicode version of Delphi, so you should be using UnicodeString for everything, not AnsiString at all. TIdDecoderMIME.DecodeString() and BytesToString() (and TEncoding.GetString()) return a UnicodeString in Delphi 2009 and later. (06-25-2019, 03:06 PM)staff@ergosoft.it Wrote: if the file to be decoded is "simple" ... to the work .... That can easily happen when you deal in Unicode->ANSI conversions. Such conversions are lossy. Stick with Unicode for everything, eg: Code: varCode: procedure StrToFile(const FileName, SourceString: String);(06-25-2019, 04:00 PM)staff@ergosoft.it Wrote: Base64 := BytesToString(IDBytes, IndyTextEncoding_ANSI); There is no IndyTextEncoding_ANSI in Indy. The equivalent of TEncoding.ANSI is IndyTextEncoding_OSDefault. That being said: (05-11-2019, 02:48 PM)staff@ergosoft.it Wrote: I try to decode my string on line here https://www.base64decode.org/ and work... ! The base64 data you showed originally DOES NOT decode to anything that resembles text. It is, in fact, binary data instead. Which makes sense, as you are saving the data to a p7m file, which is an encrypted email format, and encrypted data is binary. So, you should not be decoding the base64 to a String at all. Decode it to bytes only, and then save those bytes as-is to your p7m file, eg: Code: varCode: procedure BytesToFile(const FileName: String; const SourceBytes: array of Byte);RE: Decode Base64 into Memo or file - staff@ergosoft.it - 06-26-2019 Hi Rlebeau !!! OK Resolved.... your suggestions were precious! Many thanks Alessandro Romano |