Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

July 19, 2004 12:00 AM

Access Denied: A Basic File Encryption Tool

Windows IT Pro
InstantDoc ID #43089
Rating: (0)

I need a basic file encryption tool so that I can FTP and email files to business partners with whom no VPN is available. Does Windows provide any built-in utilities for encrypting files?

You apparently already realize that Encrypting File System (EFS) won't help you because EFS protects files while they're on your hard disk but decrypts them before they're transmitted. No built-in commands are available, but a COM interface called CAPICOM.dll provides easy-to-use, high-level access to Windows' CryptoAPI. Moreover, sample scripts that use the interface and let you encrypt and decrypt files from the command prompt are available in the Microsoft Platform Software Development Kit (SDK). These VBScript scripts are easy to modify, although you probably won't need to change them. You can learn more about CAPICOM at http://www.microsoft.com/msdownload/platformsdk/sdkupdate/default.htm?p=/msdownload/platformsdk/sdkupdate/psdkredist.htm, and you can download the SDK from http://www.microsoft.com/msdownload/platformsdk/sdkupdate.

After you install the SDK, look in the C:\Program Files\Microsoft SDK\Samples\security\capicom\vbs folder. Two scripts, cencrypt.vbs and cdecrypt.vbs, let you encrypt and decrypt a file from the command line, respectively. You can specify the password from which the encryption key is generated, the encryption algorithm, and the key length, as well as the input and output file names. To get help for either utility, simply enter the command followed by the -? parameter. The following sample command uses Advanced Encryption Standard (AES) to encrypt a file called transactions.txt:

cscript cencrypt.vbs encrypt
  -alg AES -length MAX
  transactions.txt
  e-transactions.txt
  sk343jf92k3j43023hgsl

To decrypt e-transactions.txt to a file named d-transactions.txt, use the command

cscript cencrypt.vbs decrypt
  e-transactions.txt
  d-transactions.txt
  sk343jf92k3j43023hgsl

The only gotcha with cencrypt.vbs is that it works only on text files--it doesn't handle other files, such as spreadsheets, databases, or files that contain non-ASCII characters. You can work around this limitation simply by converting the file to Base64-encoded format before you encrypt it, then backing out of Base64 encoding after you decrypt the file.

A public-domain utility called base64 can help; the utility is available at http://www.fourmilab.ch/webtools/base64. Written by John Walker, one of the original authors of AutoCAD, the base64 utility is simple and works well. The example below illustrates how to use Cencrypt and Base64 together.

base64 /e transactions.db
  b64-transactions.db
cscript cencrypt.vbs encrypt 
  -alg AES -length MAX
  b64-transactions.txt
  e-transactions.txt
  sk343jf92k3j43023hgsl
cscript cencrypt.vbs decrypt
  e-transactions.txt
  b64-transactions.txt
  sk343jf92k3j43023hgsl
base64 /d b64-transactions.db
  transactions.db

After running the commands, you can use the Comp command to verify that the original file (transactions.db) and the decrypted file (d-transactions.db) match.

To use Cencrypt on a computer, simply ensure that Windows Script Host (WSH) is installed and register CAPICOM.dll. WSH is installed by default on most Windows systems. To register CAPICOM.dll, simply install the downloaded file in %winroot% and run the command

regsvr32 capicom.dll

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.