#1 2018-05-11 12:25:56

jaclas
Member
Registered: 2014-09-12
Posts: 215

TAESWriteStream - chaining mode

What chaining mode does TAESWriteStream use?

Offline

#2 2018-05-11 18:49:17

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TAESWriteStream - chaining mode

Only AES cypher without chaining (ECB).
So it is not very secure.

Offline

#3 2018-05-11 18:53:26

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: TAESWriteStream - chaining mode

So how to encrypt streams? By copying them to the array?

Offline

#4 2018-05-11 20:23:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TAESWriteStream - chaining mode

Which array are you talking about?

Offline

#5 2018-05-12 07:29:47

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: TAESWriteStream - chaining mode

array of byte :-)
I need to encrypt stream (with chaining mode), how to do it best?

Like this?

procedure AESstreamCrypt(const aInStream, aOutStream: TStream; const aKey: TBytes; const aIV: TAESBlock);
var
  lInput : TBytes;
  lOutput : RawByteString;
begin
  lAES := TAESCBC.Create(aKey[0], lKeySize);
  try
    lAES.IV := aIV;
    aInStream.Position := 0;

    // copy aInStream to TBytes local variable
    SetLength(lInput, aInStream.Size);
    aInStream.ReadBuffer(lInput[0], aInStream.Size);

    //encypt TBytes
    lOutput := lAES.EncryptPKCS7(lInput, False);

    //copy encrypted data do output stream
    aOutStream.Write(lOutput[1], Length(lOut));
  finally
    lAES.Free;
  end;
end;

Offline

#6 2018-05-12 08:29:46

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TAESWriteStream - chaining mode

Yes, or just encrypt in-place if aInSTream is a memory stream.

Offline

Board footer

Powered by FluxBB