• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Safely erase (Delete) Files

Started by Theo Gottwald, November 22, 2014, 11:25:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

As we all know, Files can be reconstructed if you simply use the PB "KILL" command.
There are mostly two standards to safely erase files,
1. The US DoD 5220.22-M standard (3-pass and 7-pass)
2. the Gutmann method, which overwrites the file with random data 35 times.
File-Buffering should be taken into account anyway.

I have implemented two versions, one fast version for files in the range up to several hundred MB (32-bit).
And one version that is really slow - for very large files.
Now maybe somebody want to improve or give a comment on it.


'----------------------------------------------------------------------------

'----------------------------------------------------------------------------
' Überschreibt Datei 9 mal mit blinkenden Bits und Zufallszeichen
' löscht Datei dann
'
FUNCTION Kill_DoD(BYVAL U01 AS STRING) AS LONG
' These are the necessary Declarations for the Variables (MACROS)
G_REG
G_T01
G_S03
G_B03
LOCAL Q01,Q02 AS QUAD
' This function fills a string with Random Bytes, here is the RANDOMIZE for it
S03=RandBytes$(0)
IF zero(ISFILE(U01)) THEN R01=0:GOTO enx
' These are changing Bits (blinking bits)
B01=&B10101010:S01=CHR$(B01)
B02=&B01010101:S02=CHR$(B02)
' Länge der Datei holen
Q01=LOF(T01)
FOR R02=1 TO 35
S03=STRING$(Q01,S01)
R01=Overwrite_File(U01,S03)
IF R01=0 THEN GOTO ero
S03=STRING$(Q01,S02)
R01=Overwrite_File(U01,S03)
IF R01=0 THEN GOTO ero
' This function fills a string with Random Bytes, here is the RANDOMIZE for it
S03=RandBytes$(Q01)
R01=Overwrite_File(U01,S03)
IF R01=0 THEN GOTO ero
NEXT
' Jetzt Datei löschen
KILL U01
R01=1
enx:
  FUNCTION=R01
EXIT FUNCTION
ero:
R01=0:GOTO enx
END FUNCTION
'----------------------------------------------------------------------------

'----------------------------------------------------------------------------
' Überschreibt Datei U01 mit Muster U02, leert Puffer
'
FUNCTION Overwrite_File(BYVAL U01 AS STRING, BYREF U02 AS STRING) AS LONG
' These are the necessary Declarations for the Variables (MACROS)
G_REG
G_S01
LOCAL T01 AS DWORD
ON ERROR GOTO ero
T01=LEN(U02)
IF zero(T01) THEN GOTO ero
R01=FREEFILE
OPEN U01 FOR BINARY ACCESS READ WRITE LOCK READ WRITE AS R01
SEEK #R01,1
PUT$ #R01,U02
FLUSH #R01
CLOSE R01
OPEN U01 FOR BINARY ACCESS READ WRITE LOCK READ WRITE AS R01
GET$ #R01,T01,S01
FLUSH #R01
CLOSE R01
IF S01<>U02 THEN R02=0 ELSE R02=1
enx:
  FUNCTION=R02
EXIT FUNCTION
ero:
CLOSE R01
R02=0
GOTO enx
END FUNCTION
'----------------------------------------------------------------------------

'----------------------------------------------------------------------------
' Überschreibt große Datei
' 40 mal mit Zufallszeichen
' löscht Datei dann
'
FUNCTION Kill_large(BYVAL U01 AS STRING) AS LONG
' These are the necessary Declarations for the Variables (MACROS)
G_REG
G_S01
LOCAL Q01,Q02 AS QUAD
G_T01
ON ERROR GOTO ero
FOR T01=0 TO 40
R01=FREEFILE
OPEN U01 FOR BINARY ACCESS READ WRITE LOCK READ WRITE AS R01
Q01=LOF(R01)
FOR Q02=1 TO Q01
    SEEK #R01,Q02
    PUT$ #R01,CHR$(RND(0,255))
NEXT
FLUSH #R01
CLOSE R01
NEXT
KILL U01
R01=1
enx:
  FUNCTION=R02
EXIT FUNCTION
ero:
CLOSE R01
R02=0
GOTO enx
END FUNCTION
'----------------------------------------------------------------------------

'----------------------------------------------------------------------------