package Encryption
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
func SecureDelete(FilePath string) error {
|
|
var (
|
|
file *os.File
|
|
fileInfo os.FileInfo
|
|
size int64
|
|
zeroBytes []byte
|
|
e error
|
|
)
|
|
file, _ = os.OpenFile(FilePath, os.O_RDWR, 0666)
|
|
defer file.Close()
|
|
// Find out how large is the target file
|
|
fileInfo, e = file.Stat()
|
|
if e != nil {
|
|
return e
|
|
}
|
|
size = fileInfo.Size()
|
|
// Create byte array filled with zero's
|
|
zeroBytes = make([]byte, size)
|
|
_, e = file.Write([]byte(zeroBytes))
|
|
if e != nil {
|
|
return e
|
|
}
|
|
e = os.Remove(FilePath)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
return nil
|
|
}
|