ich hab mir mal das filecrypt beispiel angeguckt von jus.
Jez hab ich versucht das n bisschen abzuändern, dass anstatt einer Datei direkt ein Stream verwendet wird. Aber irgendiwe klappt das nich. Da kommt dann ein Fehler mit der Meldung "Stream-Lesefehler" und der tritt in der procedure:
Delphi-Quellcode:
procedure TDECCipher.EncodeStream(const Source, Dest: TStream; const DataSize: Int64; const Progress: IDECProgress);
begin
DoCodeStream(Source, Dest, DataSize, Context.BlockSize, Encode, Progress);
end;
auf.
Hier mal meine abgeänderte version:
Delphi-Quellcode:
procedure EncodeMStream(const ADestFilename: String; const APassword: Binary;
ACipher: TDECCipherClass = nil; AMode: TCipherMode = cmCTSx;
AHash: TDECHashClass = nil);
var
Dest: TStream;
procedure Write(const Value; Size: Integer);
begin
Dest.WriteBuffer(Value, Size);
end;
procedure WriteByte(Value: Byte);
begin
Write(Value, SizeOf(Value));
end;
procedure WriteLong(Value: LongWord);
begin
Value := SwapLong(Value);
Write(Value, SizeOf(Value));
end;
procedure WriteBinary(const Value: Binary);
begin
WriteByte(Length(Value));
Write(Value[1], Length(Value));
end;
var
Sourcestr: TMemoryStream;
Seed: Binary;
begin
{if ASourceFileName=ADestFilename then
begin
showmessage('Source file and destination file must not be equal!');
exit;
end; }
ACipher := ValidCipher(ACipher);
AHash := ValidHash(AHash);
Seed := RandomBinary(16);
//Source := TFileStream.Create(ASourceFileName, fmOpenReadWrite);
Sourcestr:=TMemorystream.Create();
try
sourcestr.WriteComponent(Form1.listview1);
Dest := TFileStream.Create(ADestFilename, fmCreate);
try
with ACipher.Create do
try
Mode := AMode;
Init(AHash.KDFx(APassword, Seed, Context.KeySize));
WriteLong(Identity);
WriteByte(Byte(Mode));
WriteLong(AHash.Identity);
WriteBinary(Seed);
WriteLong(Sourcestr.Size);
EncodeStream(Sourcestr, Dest, Sourcestr.Size);
WriteBinary(CalcMAC);
finally
Free;
end;
finally
Dest.Free;
end;
//ProtectStream(Source);
finally
Sourcestr.Free;
end;
//DeleteFile(AFileName);
end;
Was habe ich falsch gemacht?