Jukka
      
Beiträge: 107
Win XP Pro
Delphi 7
|
Verfasst: Do 12.10.06 16:22
Hallo,
Ich möchte eine Funktion umschreiben. Die funktion Decodiert eine Datei, das ist bei mir aber etwas unpraktisch daher will ich diese Funktion mit Streams nutzen. Ich benutze die AESdll und eine lib von hier:
www.matiasmoreno.com.../libs/delphi/aesdll/
Die Funktion EncodeFile konnte ich in EncodeStream umschreiben wenn ich das aber mit DecodeFile mache wird das ergebniss ein endlos großer Stream = Abstürz.
Orginal:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
| procedure DecodeFile (skey, in_filename, out_filename : string); var f1, f2 : File; Key : KeyBlk; LastIb, Ib, Ob : IoBlk; Cx : AESctx; x, i : integer; begin BlkLen := 16; KeyLen := 16; ZeroAESctx (Cx); SetStringKey (Key, KeyLen, skey); AesDecKey (Key, KeyLen, Cx); AssignFile (f1, in_filename); Reset (f1, 1); AssignFile (f2, out_filename); Rewrite (f2, 1); BlockRead (f1, x, 4); FillChar (LastIb, BlkLen, 0); While (x > BlkLen) do begin BlockRead (f1, Ib, BlkLen); AesDecBlk (Ib, Ob, Cx); For i := 0 To BlkLen-1 do Ob.IO[i] := Ob.IO[i] Xor LastIb.IO[i]; Move (Ib, LastIb, BlkLen); BlockWrite (f2, Ob, BlkLen); dec (x, BlkLen); end; BlockRead (f1, Ib, BlkLen); AesDecBlk (Ib, Ob, Cx); BlockWrite (f2, Ob, x); CloseFile (f1); CloseFile (f2); end; |
In Encode habe ich das gleiche Prinzip wie jetzt hier benutzt und da geht es aber
Meine Umgeschreibene:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28:
| procedure DecodeStream (skey: string; inStream, outStream : TStream); var Key : KeyBlk; LastIb, Ib, Ob : IoBlk; Cx : AESctx; x, i : integer; begin BlkLen := 16; KeyLen := 16; ZeroAESctx (Cx); SetStringKey (Key, KeyLen, skey); AesDecKey (Key, KeyLen, Cx); inStream.Read(x,4); FillChar (LastIb, BlkLen, 0); While (x > BlkLen) do begin inStream.Read(Ib, BlkLen); AesDecBlk (Ib, Ob, Cx); For i := 0 To BlkLen-1 do Ob.IO[i] := Ob.IO[i] Xor LastIb.IO[i]; Move (Ib, LastIb, BlkLen); outStream.Write(Ob, BlkLen); dec (x, BlkLen); end; inStream.Read(Ib, BlkLen); AesDecBlk (Ib, Ob, Cx); outStream.Write(Ob, x); end; |
Meine Funktion muss irgendwo einen fehler haben nur ich weiß nicht wo
Kann mir da jemand helfen?
MfG Jukka
|