Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#1

Mit DEC verschlüssel. Wie groß ist die Schlüssellänge?

  Alt 25. Mär 2007, 05:21
Ich nutze diesen Code, um eine Datei mit dem DEC zu verschlüsseln:
Delphi-Quellcode:
////////////////////////////////////////////////////////////////////////////////
// Comment : Encodes a file
// Arguments : Filename, Folder, PW: String; FileHeader: TFileHeader;
// hWnd: THandle
// Result : Boolean

function TEncodeThread.EncodeFile(Filename, Folder, PW: string;
  FileHeader: TFileHeader; hWnd: THandle): Boolean;
var
  SrcStream: TStreamProgressAdapter;
  DestStream: TFileStream;
  Len: Integer;
  Buffer: Pointer;
begin
  result := False;
  // open source stream
  SrcStream := TStreamProgressAdapter.Create(TFileStream.Create(Filename, fmOpenRead or fmShareDenyNone), hWnd);
  if Assigned(SrcStream) then
  begin
    try
      // create destination stream
      DestStream := TFileStream.Create(IncludeTrailingPathDelimiter(Folder)+ ExtractFilename(Filename) + EXTENSION,
        fmCreate);
      if Assigned(DestStream) then
      begin
        try
          // write the head into the stream
          DestStream.Write(FileHeader, sizeof(TFileHeader));
          // prepare vor encoding
          with DefCipherClass.Create(PW, nil) do
          begin
            Mode := cmCBC;
            InitKey(PW, nil);
            // alocate memory for the buffer
            GetMem(Buffer, 1024);
            try
              // as long as we have not reached the end of the source stream
              while (SrcStream.Position < SrcStream.Size) and (Terminated = False) do
              begin
                // how much to read
                if SrcStream.Size - SrcStream.Position > BlockSize then
                  Len := BlockSize
                else
                  Len := SrcStream.Size - SrcStream.Position;
                // read into the buffer
                SrcStream.ReadBuffer(Buffer^, Len);
                // encode the buffer
                EncodeBuffer(Buffer^, Buffer^, len);
                // write the buffer
                DestStream.WriteBuffer(Buffer^, Len);
              end;
            finally
              // clean up the buffer
              FreeMem(Buffer);
            end;
          end;
        finally
          // free the destination stream
          FreeAndNil(DestStream);
        end;
      end
      else // could not create the destination stream
      begin
        RaiseLastOSError();
        exit;
      end;
    finally
      // free the source stream
      FreeAndNil(SrcStream);
    end;
  end
  else // could not open the source stream
  begin
    RaiseLastOSError();
    exit;
  end;
  // we didn't exit the function early, everything went O.K.
  result := True;
end;
Wobei
Delphi-Quellcode:
  DefCipherClass: TCipherClass = TCipher_Rijndael;
  DefHashClass: THashClass = THash_SHA1;
Wie groß ist da jetzt eigentlich die Schlüssellänge?
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat