procedure TFormMain.Button4Click(Sender: TObject);
const
keyBytes:
array [0 .. 31]
of Byte = ($2A, $5F, $CB, $17, $91, 210, $2F, $B6, 2, $45, $B3, $D8, $36, $9E, $D0, $B2, $C2, $73, $71, $56, $3F, $BF, $1F, 60, $9E, $
DF, $6B, $11, 130,
90, $5D, 10);
var
FS: TFileStream;
Key, EncryptedData: TBytes;
DecompressionStream, ZLibStream: TZDecompressionStream;
OutputStream: TFileStream;
ctx: TAESContext;
aesblck: TAESBlock;
i: Integer;
Res: TBytes;
BytesStream: TBytesStream;
MemoryStream: TMemoryStream;
var
fileContent, initVector: TArray<Byte>;
begin
{*
fileContent := TFile.ReadAllBytes('enc.txt');
SetLength(EncryptedData, length(fileContent) - $38);
SetLength(initVector, $10);
TArray.Copy<Byte>(fileContent, EncryptedData, $38, 0, length(EncryptedData));
TArray.Copy<Byte>(fileContent, initVector, $24, 0, $10);
for i := 1 to 16 do
aesblck[i - 1] := Byte(initVector[i]);
ctx.IV := aesblck;
AES_CBC_Init_Decr(keyBytes, 128, aesblck, ctx);
SetLength(Res, 4096);
AES_CBC_Decrypt(@EncryptedData[1], @Res[1], length(EncryptedData), ctx);
Exit;
*}
FS := TFileStream.Create('
enc.txt', fmOpenRead);
try
FS.Seek($24, soBeginning);
SetLength(Key, 16);
FS.
Read(Key[0], length(Key));
FS.Seek($38, soBeginning);
SetLength(EncryptedData, FS.Size - $38);
FS.
Read(EncryptedData[0], length(EncryptedData));
for i := 1
to 16
do
aesblck[i - 1] := Byte(Key[i]);
ctx.IV := aesblck;
AES_CBC_Init_Decr(keyBytes, 128, aesblck, ctx);
SetLength(Res, 4096);
AES_CBC_Decrypt(@EncryptedData[1], @Res[1], length(EncryptedData), ctx);
finally
FS.Free;
end;
// Die Resultate beider Codeblöcke (oben der kommentierte und der danach) sind gleich
BytesStream := TBytesStream.Create(Res);
try
ShowMessage(BytesStream.Size.ToString);
ZLibStream := TZDecompressionStream.Create(BytesStream);
try
ShowMessage(ZLibStream.Size.ToString);
OutputStream := TFileStream.Create('
dec.txt', fmCreate);
try
OutputStream.CopyFrom(ZLibStream, 0);
finally
OutputStream.Free;
end;
finally
ZLibStream.Free;
end;
finally
BytesStream.Free;
end;
end;