What I'm trying to do is essentially shred a file. I was recently in a security protocol meeting at my company, and one of the speakers showed us how he could recover a file that was put in the trash folder and then emptied from the hard drive. Being a new guy on the IT team, they asked me if I could find a way to "shred" the file. Essentially what I want to do is this:
-drag/send a file to a folder/applet:
-have an AppleScript open the file in text edit:
-use a "randomly" generated ASCII string (see below) to encrypt/corrupt the text:
-save the file, and then delete it with the "remove" shell script:
-if at all possible, find a way to instantly rewrite the part of the drive that contained the file previously:
This is what I have so far. It's just pieced from previous projects I did and some looking online.
--this is the "random" generator
set passphrase to ""
repeat with x from 1 to 100
set randomChar to ASCII character (random number from 50 to 100)
set passphrase to passphrase & randomChar
end repeat
--end generator
tell application "Finder"
set sel to selection
if sel is not {} then
set als to sel's item 1 as alias
set aPath to POSIX path of als
set oldPath to aPath & ".old"
set oldPath2 to quoted form of oldPath
set aPath2 to quoted form of aPath
--display dialog "Enter a password for encryption" default answer "password"
set password1 to passphrase
set scRi to "openssl des3 -in " & oldPath2 & " -out " & aPath2 & " -k " & quoted form of password1
set RenameToOld to "mv " & aPath2 & " " & oldPath2
set DeleteOld to "srm " & oldPath2
--display dialog scRi
tell application "Terminal"
activate
do shell script (RenameToOld)
do shell script (scRi)
do shell script (DeleteOld)
end tell
end if
end tell
end open
sorry if the spacing is off. I keep getting an error saying that the variable "passphrase" is not defined, even though I tried to fix it plenty of times. It seems to corrupt any file it is handed, but I don't know why or how. If somebody could figure out how to get it to work, I would be very grateful.
The srm
command is gone in 10.12, along with Finder's Secure Delete option. Apple sensibly eliminated them as they don't work on SSDs, nor do they destroy previously written or backup copies. As the new IT guy you really need to educate yourself before you take responsibility for anything security-related. See also: Security Theater.