My other post on this was implicating a Base64 problem. I have done some testing and have discovered that the problem is actually BlowFish in Lazarus 1.9 / Fpc 3.1.1.
Method:
I installed both Laz 1.8 / Fpc 304 and Laz 1.9 / Fpc 3.1.1 on my development machine using fpcupdeluxe-x86_64-win64.exe v1.6.0m from
https://github.com/newpascal/fpcupdeluxe/releases/tag/v1.6.0m.
Reason:
I had to do this for testing purposes. I had to upgrade my Fpc because FBAdmin component is busted in Fpc 304. However, I'm still stuck, because BlowFish is now busted in Fpc 3.1.1. I need a version combo where FBAdmin and BlowFish and Base64 work correctly.
The code below shows the results of my running the very same project in the two different environments. My OS is Windows Server 2016.
Laz18, Fpc304 works perfectly. No Memory Access errors.
Laz19, Fpc311 fails at the places indicated.
The comment "Correct" only means that it works, not that I am a Base64 or BlowFish expert.
Laz18 Fpc304: Input: MyPlainText
Laz19 Fpc311: Input: MyPlainText
First Part ----------
Encrypt using Blowfish, then Encode using Base64
Laz18 Fpc304: Bytes BlowFish Enc: b?#??Jo?d|??QK // Correct
Laz19 Fpc311: Bytes BlowFish Enc: bµ#ëì¯Joàd|’'#14'ÙQK // BlowFish goes wrong, right from the start
Laz18 Fpc304: Base64 Encoded: YrUj6+yvSm/gZHySDtlRSw== // Correct
Laz19 Fpc311: Base64 Encoded: YsK1I8Orw6zCr0pvw6BkfOKAmQ7DmVFL // Wrong, but understandable since the input was different
www.base64encode.org Encoded 304's output: Yj8jPz9Kbz9kfD8OP1FL // Disagrees with 304, but who cares.. 304 works
www.base64encode.org Encoded 311's output: YsK1I8Orw6zCr0pvw6BkfOKAmScjMTQnw5lRSw== // Disagrees with 311, but input was different, so understandable
// 304 has correct output, so I can use it for other things. It is both encrypted and MIME'd
// So now comes the time I want to reverse the process and get the original text MyPlainText...
// Second Part -----------
// Decode using Base64, then Decrypt using BlowFish
Laz18 Fpc304: Base64 Decoded: b?#??Jo?d|??QK // Correct
Laz19 Fpc311: Base64 Decoded: bµ#ëì¯Joà d|’'#14'ÙQK // Wrong, but understandable since the input was different
www.base64encode.org Decoded of 304's output: b#Jod|QK // Disagrees with 304, but who cares.. 304 works
www.base64encode.org Decoded of 311's output: bµ#ëì¯Joàd|’ÙQK // Disagrees with 311, but input was different, so understandable
Laz18 Fpc304: Base64 Dec: MyPlainText // Correct
Laz19 Fpc311: Base64 Dec: Memory Access Error // Memory access error means I cannot use this in a production system.
// 304 works without error. 311 has errors, shown in comments above.
Thanks in advance for any help you can provide. Code shown below.
procedure TfrmMain.Button2Click(Sender: TObject);
var
mime_str_in, mime_str_out: String;
plain_text: String;
enc_str, dec_str: RawByteString;
bfsh_enc_strm: TBlowFishEncryptStream;
bfsh_dec_strm: TBlowFishDecryptStream;
strm: TStringStream;
begin
master_pwd := '12345678';
plain_text := 'MyPlainText';
ShowMessage('plain_text: ' + plain_text);
//--- Encrypt first
strm := TStringStream.Create('');
bfsh_enc_strm := TBlowfishEncryptStream.Create(master_pwd, strm);
bfsh_enc_strm.WriteAnsiString(plain_text);
bfsh_enc_strm.Flush;
enc_str := strm.DataString;
ShowMessage('Encrypted String: ' + enc_str);
// Now MIME encode it
mime_str_in := EncodeStringBase64(enc_str);
ShowMessage('mime_text: ' + mime_str_in);
bfsh_enc_strm.Free;
strm.Free;
// Encryption/Encoding completed
// Decode MIME first, before we decrypt
dec_str := DecodeStringBase64(PChar(mime_str_in.ToCharArray), False);
ShowMessage('dec_str: ' + dec_str);
if SameText(enc_str, dec_str) then
ShowMessage('enc_str and dec_str match')
else
ShowMessage('enc_str and dec_str DO NOT match');
// Now, Decrypt
strm := TStringStream.Create(dec_str);
bfsh_dec_strm := TBlowfishDecryptStream.Create(master_pwd, strm);
dec_str := bfsh_dec_strm.ReadAnsiString;
ShowMessage('dec_str: ' + dec_str);
if SameText(plain_text, dec_str) then
ShowMessage('enc_str and dec_str match')
else
ShowMessage('enc_str and dec_str DO NOT match');
end;