Blog Archives

File Shredder Shortcut using SDelete in Windows XP, Vista, 7

Computer enthusiasts have been using file shredders to delete files for many years. Sysinternals makes a very cool utility called “SDelete” that “shreds” a file

See below for batch file code snippet to use with SDelete. Add to your “User/Administrator/AppData/Roaming/Microsoft/Windows/SendTo” (In Vista/7/Serv08) or “Documents and Settings\%username%\SendTo” (In XP).

(%APPDATA% environment variable actually points to “C:\users\\AppData\Roaming”)

I have modified the code below from it’s original source on blog (see references) to 3 passes instead of four. See wikipedia page for more information on data remanence. If the script runs slow on your system consider decreasing this to 3 or 4.


@echo off
:START
if "%~f1"=="" (
echo No more args given. Done.
exit /b 0
)
:WORK
ECHO Y| cacls %1 /T /C /G Administrators:F
attrib -h -s -r -a %1 /S /D
attrib -h -s -r -a %1\*.* /S /D
sdelete -p 7 -s -q %1
:NEXTARG
shift
goto START

Addendum 2012.11.09
Windows 7 environment path seems to be buggy at times. Absolute references to executables is more reliable.

@echo off
:START
if "%~f1"=="" (
echo No more args given. Done.
exit /b 0
)
:WORK
ECHO Y| C:\Windows\System32\cacls.exe %1 /T /C /G Administrators:F
C:\Windows\System32\attrib.exe -h -s -r -a %1 /S /D
C:\Windows\System32\attrib.exe -h -s -r -a %1\*.* /S /D
C:\Windows\System32\sdelete.exe -p 7 -s -q %1
:NEXTARG
shift
goto START


Note:
Any snippets may have been condensed from their original sources for brevity. See references for original articles.

All server side code examples are in C# .Net.

References
Sysinternals, Blog: “My Handy sdelete scripts”, Soulstace, http://forum.sysinternals.com/my-handy-sdelete-scripts_topic6065.html
Wikipedia, “Data Remanance”, http://en.wikipedia.org/wiki/Data_remanence
HowToGeek, http://www.howtogeek.com/howto/windows-vista/customize-the-windows-vista-send-to-menu/

Quick .Net Encryption Reference

The code below represents a very basic .NET encryption class which has been tested and should work in your application – simply plug and play. :)

Contains two static methods that can be called without needing to instantiate the class.

Keep in mind the initialization vector below (indicated by rgbIV) is generic, and you will need to come up with your own. Remember not to share this. Even if the password is compromised, the attacker would also need to know the initialization vector to crack your value.

Also note the code which has been commented out. This illustrates cases where passwords and/or IV can be statically set in the class and/or shared based on value passed in for password parameter.

Sharing IV and password or storing either statically is a security risk and could cause errors depending on byte differences of the values. If you statically store these values, you will still create secure cipher text, but it will be much easier to crack.

Enjoy. ;)

using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;

namespace AIS.Common.Crypto
{

public static class Rijndael
{
    public static string Encrypt(string ClearText,string password)
    {

        byte[] clearTextBytes = Encoding.UTF8.GetBytes(ClearText);

        System.Security.Cryptography.SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();

        MemoryStream ms = new MemoryStream();
        
        byte[] rgbIV = Encoding.ASCII.GetBytes("example");
        //byte[] key = Encoding.ASCII.GetBytes("longerexample");

        //byte[] rgbIV = Encoding.ASCII.GetBytes(password);
        byte[] key = Encoding.ASCII.GetBytes(password);

        CryptoStream cs = new CryptoStream(ms, rijn.CreateEncryptor(key, rgbIV),
   CryptoStreamMode.Write);

        cs.Write(clearTextBytes, 0, clearTextBytes.Length);

        cs.Close();

        return Convert.ToBase64String(ms.ToArray());
    }

    public static string Decrypt(string EncryptedText, string password)
    {
        byte[] encryptedTextBytes = Convert.FromBase64String(EncryptedText);

        MemoryStream ms = new MemoryStream();

        System.Security.Cryptography.SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();


        byte[] rgbIV = Encoding.ASCII.GetBytes("example");
        //byte[] key = Encoding.ASCII.GetBytes("longerexample");

        //byte[] rgbIV = Encoding.ASCII.GetBytes(password);
        byte[] key = Encoding.ASCII.GetBytes(password);

        CryptoStream cs = new CryptoStream(ms, rijn.CreateDecryptor(key, rgbIV),
        CryptoStreamMode.Write);

        cs.Write(encryptedTextBytes, 0, encryptedTextBytes.Length);

        cs.Close();

        return Encoding.UTF8.GetString(ms.ToArray());

    }

}
}

References:
Wikipedia – Encryption, http://en.wikipedia.org/wiki/Encryption

Follow

Get every new post delivered to your Inbox.