Click here to Skip to main content
Click here to Skip to main content

File Security (fs) Utility for the Command Line

, 13 Aug 2002
Rate this:
Please Sign up or sign in to vote.
.NET command line utility, implementing file security through symmetric encryption.

Abstract

The file security (fs) utility implements the CCrypto and CDir classes I presented earlier on this site. The purpose of this article is to demonstrate how these classes can be used along with managed extensions for C++, to create a usable command line utility.

Before I go behind the scenes, let me go over some of the code features this utility demonstrates. The utility implements parameter processing, file filtering & directory recursion, file wiping, encryption, decryption, and MD5 & SHA-1 hashing. The encryption and decryption is done through the Rijndael algorithm with a 256 bit key space.

Although the user interface may not be exactly user friendly, I believe there is still a place for command line utilities.

The syntax of the command:

 fs [-?] [-r] [-q] 
   { [-w #] | [-e] | [-d] | [-l] | [-sha] | [-md5] [-KEY drv:\file] }
   { [-p password] | [-k drv:\file] }
     [-x .ext] [-o drv:\folder] [[drv:\file]...]

The parameter definition:

 -w #   Wipe file with # passes (default is 7 wipes)
 -e     Encrypts file(s) (requires parameters {-p | -f})
 -d     Decrypts file(s) (requires parameters {-p | -f})
 -sha   SHA-1 signature
 -md5   MD5 signature
 -l     Lists file(s) only
 -q     quiet mode
 -KEY   Make key file
 -p     Sets the password for encryption or decryption
 -k     Sets key file for encryption or decryption
 -r     Recursive on sub directories and files
 -x     Set file extension for encrypted file(s) (default is .crypt)
 -o     Set directory location for encrypted files
 -?     This help screen

Example usage

To wipe all the *.txt files in the current directory:

fs -w 10 *.txt

To encrypt all the *.msg and *.txt files on the drive to the folder c:\encrypted using the key file c:\key.zzz.

fs -r -e -o c:\encrypted -k c:\key.zzz c:\*.msg  c:\*.txt

Behind the scenes

The _tmain() function is the entry point for the executable. The _main() function instantiates the CFileSecurity and the CDir classes into objects and then processes the parameters taken through (argc, *argv[]). The parameter switches set the attributes of the objects which determine the utility's characteristics.

There are actually three classes that make up the utility: CCrypto, CFileSecurity, and CDir. The CDir class processes the files and folders. The CCrypto class contains the methods to wipe, encrypt, decrypt, create file keys and hash files. The CFileSecurity is the middle man that sits between the two objects.

The CFileSecurity class creates an abstraction layer between the file processing of the CDir class and the CCrypto class. In the abstraction layer, attributes are set according to the command line switches. Before file processing begins, the CFileSecurity::SettingsOK() method does some validity checking on the switches. An example of a check would be to ensure that we have a key when encrypting or decrypting.

After the validity checking the CCrypto class is instantiated into an object by the CFileSecurity::InitializeCrypto() method. The method calls on the appropriate CCrypto constructor and sets some attributes. The CFileSecurity::ProcessFile(FilePath) method determines which of the CCrypto methods to call to process the file.

The CDir::dir method processes the files that meets the user defined filter in the current directory. Each file that matches the filter, is passed on to the CFileSecurity::ProcessFile for processing. If recursion is enabled, folder paths are also processed by passing each path back into the dir method.

Issues

There are no issues that come to mind, using the utility. There could be a list made of improvements that could be made though. One example that I could think of would be to prevent encrypting the keys you use to encrypt.

I do not really like the way I handled the command line parameters. If some one knows of a more elegant way I would like to know.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Bill Ferreira
Web Developer
Canada Canada
No Biography provided

Comments and Discussions

 
GeneralFile Wiping PinmemberBill Ferreira18-Sep-03 11:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 14 Aug 2002
Article Copyright 2002 by Bill Ferreira
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid