Results 1 to 13 of 13

Thread: Secure Delete [Resolved by Alphanos]

  1. #1

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Secure Delete [Resolved by Alphanos]

    Hi,

    How can i securely delete a file in VB. I am writing an encryption utility and need to delete the source file securly after the encryption. By securly i mean, it can not be recovered easily. How can i achive that in vb.

    Thanks for your help.

    Danial
    Last edited by Danial; Jan 6th, 2002 at 12:10 AM.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    I'm in front of the computer.
    Posts
    270
    You can simply write overtop of the file several times. Open the file for binary, and write values of 0 overtop of all bytes in the file 2-3 times. Repeat with 255, then with 0 again, then delete the file. Besides the normal deletion, which removes the info about where it is, the original information in that location will be erased and not subject to testing for ghost bytes if you repeat the writing 2-3 times. It could still be recoverable by a very good expert if you just write with 0's, 255's, and 0's again; the repeats are important.

    That's the most secure way I know of of deleting a file.
    Alphanos

  3. #3

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Thanks for responding

    do you have any example code
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  4. #4
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    I'm in front of the computer.
    Posts
    270
    IE.

    VB Code:
    1. Public Sub SecureDelete(ByRef FilePath As String)
    2.  
    3. Dim FileNum As Byte
    4. Dim i As Long
    5. Dim Value As Byte
    6.  
    7. FileNum = FreeFile
    8. Open FilePath For Binary As #FileNum
    9. Value = 0
    10. i = 1
    11. Do
    12.     If i = 3 Then Value = 255
    13.     If i = 5 Then Value = 0
    14.     Do Until EOF(FileNum)
    15.            Put #FileNum, , Value
    16.     Loop
    17.     i = i + 1
    18. Loop Until i = 7
    19.  
    20. End Sub

    Just wrote that here, so there might be a bug, test it out.

    An alternative approach would be to write random bytes over top of the file a couple times, as that way there would be data and ghost data, but it would be impossible to recover the original anyway.
    Alphanos

  5. #5

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by Alphanos
    IE.


    Just wrote that here, so there might be a bug, test it out.

    An alternative approach would be to write random bytes over top of the file a couple times, as that way there would be data and ghost data, but it would be impossible to recover the original anyway.
    Thanks for the code. It doesnt work though. The file size just keeps getting bigger and bigger and the loop doesnt end. Even one iteration takes ages.

    Anyway thanks again really appriciated.
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  6. #6
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    I'm in front of the computer.
    Posts
    270
    Oh, LOL!, I guess a line that I forgot might help.

    VB Code:
    1. Public Sub SecureDelete(ByRef FilePath As String)
    2.  
    3. Dim FileNum As Byte
    4. Dim i As Long
    5. Dim Value As Byte
    6.  
    7. FileNum = FreeFile
    8. Open FilePath For Binary As #FileNum
    9. Value = 0
    10. i = 1
    11. Do
    12.     If i = 3 Then Value = 255
    13.     If i = 5 Then Value = 0
    14.  
    15.     [b]Put #FileNum, 1, Value[/B]
    16.  
    17.     Do Until EOF(FileNum)
    18.            Put #FileNum, , Value
    19.     Loop
    20.     i = i + 1
    21. Loop Until i = 7
    22.  
    23. End Sub
    Alphanos

  7. #7

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Sorry to nag you again, but its still not working. Same problem, file just keeps growing........ The loop doesnt end.

    I am not sure why, never used file in binary mode before so dont know whats going on.

    Thanks for your patience again
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  8. #8
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    I'm in front of the computer.
    Posts
    270
    LOL, my fault for writing faulty code and not checking it.

    Lemme make a few changes here. Not quite sure what the problem was in the old one actually, but it can be fixed by using a slightly different approach.

    VB Code:
    1. Public Sub SecureDelete(ByRef FilePath As String)
    2.  
    3. Dim FileNum As Byte
    4. Dim i As Long
    5. Dim Value As Byte
    6. Dim Position As Long
    7. Dim FileLength As Long
    8.  
    9. FileNum = FreeFile
    10. Open FilePath For Binary As #FileNum
    11. FileLength = LOF(FileNum)
    12.  
    13. Do
    14.     If i = 2 Then Value = 255
    15.     If i = 4 Then Value = 0
    16.  
    17.     Position = 1
    18.  
    19.     Do Until Position > FileLength
    20.            Put #FileNum, Position, Value
    21.            Position = Position + 1
    22.     Loop
    23.     i = i + 1
    24. Loop Until i = 6
    25.  
    26. End Sub

    I'm about 99% sure that this one should work. (or at least have only some stupid syntax error that I missed)
    Alphanos

  9. #9

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Thumbs up

    At last !! Yes it works fine.

    Many thanks
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  10. #10
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    I'm in front of the computer.
    Posts
    270
    Hehe, sorry about that.
    Alphanos

  11. #11

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by Alphanos
    Hehe, sorry about that.
    No worries, that was a cool funtion, another one to my code library . Thanks for your help again
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  12. #12
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    I'm in front of the computer.
    Posts
    270
    Oh yeah, one other thing: for simplification, you should probably add the kill to the end just before the end sub. That way you don't have to call it outside. As it is right now, it'll make it impossible to get the data that was there before back, but it doesn't actually get rid of the record of where the file is, so other files can't use the HD space. So just add

    Kill FilePath

    to the end of the sub.

    Alphanos

  13. #13

    Thread Starter
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Thanks i done that a while ago !! Thanks
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width