Delphi-Kylix
  Home arrow Delphi-Kylix arrow Page 3 - Secure File Deletion in Delphi
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Secure File Deletion in Delphi
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2005-11-14

    Table of Contents:
  • Secure File Deletion in Delphi
  • Building the GUI
  • The code
  • The rest of the code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Secure File Deletion in Delphi - The code


    (Page 3 of 4 )

    I’ve tried to comment as much as possible in the code. We will start writing the two procedures that actually power this app.

    Add the following lines just above the private section:

    procedure overwriteFile(FileName: string);
    procedure getridofFile(const FileName: string);

    The following two procedures will implement the algorithm as discussed before. Add the code in the implementation section of your form:

    procedure TForm1.overwriteFile(FileName: string);
    const
      Buffer       = 1024;
      Counttowrite = 34;
      FillBuffer: array[0..5] of Integer = ($00, $FF, $00, $F0, $0F, $00);
    var
      arr: array[1..Buffer] of Byte;
      f: file;
      i, j, n: Integer;
    begin
    //open the file
      AssignFile(f, FileName);
      Reset(f, 1);
      n := FileSize(f);
    //overwrite the file 34 times
      for j := 0 to Counttowrite do
      begin
        for i := 1 to n div Buffer do
        begin
          BlockWrite(f, FillBuffer[j], Buffer);
         form1.label1.caption:=inttostr(form1.prog.Position)+'%';
      end;
      form1.prog.position:=j+1;
      end;
      CloseFile(f);
      RenameFile(FileName, ExtractFilepath
    (FileName) + '$000000.tmp');
      DeleteFile(ExtractFilepath(FileName) +
    '$000000.tmp');
      end;

     procedure TForm1.getridofFile(const FileName:
    string);
    var
      newname: string;
    begin
      // first rename the file
      newname := ExtractFilepath(FileName) +
    '$000000.tmp';

      if not RenameFile(FileName, newname) then
        raise
        Exception.CreateFmt('Cannot find %s !',
    [FileName]);

     overwriteFile(newname);

      DeleteFile(newname);

    end;

    The overwritefile procedure overwrites the contents of the file and then saves the file as ‘$000000.tmp' while updating the progressbar at the same time. The second procedure called getridofFile, grabs the file called ‘$000000.tmp', overwrites it again and then deletes it.

    The two procedures are the meat of the application, and are also very simple to use and understand. Let’s move on to the rest of the procedures needed to use the app.

    More Delphi-Kylix Articles
    More By Jacques Noah


       · A good introduction to an increasingly important subject.The author mentions the...
       · The repeated rewriting of code here will simply erase the cache multiple times...
       · Presumably renaming the file is so it's name entry is overwritten in the directory,...
       · Hi, Please be aware that main code that does the DOD wiping is grossly...
       · The code does write over the original clusters. If you check the lcn,vcn and...
     

    DELPHI-KYLIX ARTICLES

    - Delphi Wrapper Classes and XML
    - Delphi and the DOM
    - Delphi and XML
    - Internet Access: Client Service
    - Finishing the Client for an Internet Access ...
    - The Client for an Internet Access Control Ap...
    - User Management for an Internet Access Contr...
    - Important Procedures for an Internet Access ...
    - Server Code for an Internet Access Control A...
    - Constructing the Interface for an Internet A...
    - Building a Server Application for an Interne...
    - Building an Internet Access Control Applicat...
    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...
    - Using the Client Dataset in Two-Tiered Clien...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT