Click here to Skip to main content
14,237,256 members

File Encryption Utility

Rate this:
4.70 (21 votes)
Please Sign up or sign in to vote.
4.70 (21 votes)
22 Sep 2002GPL3
File Encryption Utility based on Blowfish Encryption Algorithm.

Sample Image - FileEncryption.jpg

Introduction<o:p>

After a long search for a simple and secure file encryption utility, that is simple and intuitive to use I've decided to write something of my own.<o:p>

File Encryption utility is a simple tool for encrypting both text and binary files using the blowfish encryption algorithm.<o:p>

The utility can create a self extracting encrypted file. For a deep view of how to create a self extracted executable check my other article: Creating Self-Extracted Executable .<o:p>

Features<o:p>

File Encryption Utility Has the following features:<o:p>

  • Fast & Quick File Encryption/Decryption.<o:p>
  • Internal File Wiping Utility.<o:p>
  • Creating Self-Extracting Encrypted File.<o:p>
  • Explorer Integration (through Configuration Dialog).<o:p>
  • Command Line Parameters.<o:p>

Language<o:p>

The File Encryption utility is writen in native C++ using ATL only for windowing classing.<o:p>

The usage of ATL is minimal so anyone who is not familiar with the library should be able to understand the code as well.<o:p>

Overview<o:p>

File Encryption Utility is divided to few small projects:<o:p>

  • FileEnc – The UI of the file encryption utility, also containing the Processing class which is also used by SelfExtract and it is responsible for reading/writing files.<o:p>
  • Enc_Blowfish – Blowfish encryption implementation (based upon Bruce Schneier and Jim Conger implementation).<o:p>
  • SelfExtract – Self Extracting executable "header".<o:p>
  • GenLib – Small Library holding all commonly used items in other project parts.<o:p>
  • Builder – Small Console utility for creating the final File Encryption Executable.<o:p>

GenLib – The General Library<o:p>

In order to save time and to have a central point for all general purpose classes I'm working with a static library called GenLib.<o:p>

A stripped version of the GenLib is available with the File Encryption Utility. In this version you can see the following general purpose classes:<o:p>

  • GenFiles – Openning OpenFile/SaveFile and OpenDirectory Dialog Boxes.<o:p>
  • SelfExtract – Creating Self-Extracting Executable.<o:p>
  • Thread – Implementation of a parent class for classes who want to execute code in separate thread (more information can be seen in the header – thread.h).<o:p>
  • FileWipe – Wiping a File from Hard Drive.<o:p>

All those classes are under the GenLib namespace.<o:p>

Additional Encryptions<o:p>

Inside the FileEnc project there's an interface called EncryptionInterface – implementing this interface can allow you to easily change the encryption the utility uses.<o:p>

Implementing this interface requires only stream cipher implementation and saves all the overhead of working with files.<o:p>

Blowfish implementation is statically linked to the utility in order to avoid hacking by changing the dll. With a few minutes of work the utility can support a number of encryption dlls that can be loaded at runtime based on the users decision.<o:p>

Security<o:p>

In order to make the utility the most secure I can I've tried wiping information from memory when the application closes.<o:p>

When looking at the source, you can see that I've used ZeroMemory API and few others APIs to delete information from memory (like the password used).<o:p>

When encrypting a file you can mark the 'Wipe Source After Process' checkbox and by that insure that the file you're encrypting is not accessible.<o:p>

Remarks<o:p>

Decryption does NOT verify password correctness (information is being encrypted without adding any information about the file). As a result when decrypting with the wrong password you will receive a file with junk inside - this is not a bug.<o:p>

The file encryption is based upon the password length - larger passwords equal better security.<o:p>

Although I believe that the file wiping method is very secure, to be 100% sure you should use a product dedicated to that purpose.<o:p>

Reference<o:p>

Blowfish encryption algorithm - http://www.schneier.com/paper-blowfish-fse.html

Revision History

23 Sep 2002 - Initial Revision

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Nir Dremer
Product Manager
Israel Israel
Nir is a Product Manager from Israel with past Software Engineering Experience.

You're welcome to visit his photography site:
http://www.dremer.net/

Comments and Discussions

 
GeneralBug Pin
xwcvb23-Aug-03 23:03
memberxwcvb23-Aug-03 23:03 
GeneralRe: Bug Pin
Nir Dremer24-Aug-03 3:41
memberNir Dremer24-Aug-03 3:41 
GeneralRe: Bug Pin
Bamaco215-Jan-04 9:57
memberBamaco215-Jan-04 9:57 
Generalcomparaison Pin
Fad B24-Mar-03 9:51
memberFad B24-Mar-03 9:51 
GeneralRe: comparaison Pin
Nir Dremer25-Mar-03 7:56
memberNir Dremer25-Mar-03 7:56 
GeneralVC6 Pin
Jack R13-Dec-02 1:15
memberJack R13-Dec-02 1:15 
GeneralRe: VC6 Pin
Nir Dremer13-Dec-02 1:22
memberNir Dremer13-Dec-02 1:22 
GeneralRe: VC6 Pin
Yasen Georgiew18-Apr-03 2:46
memberYasen Georgiew18-Apr-03 2:46 
Hi, Nir

Your code is really brilliant! I've tested the demo project and
I think it's very useful. That's why I've decided to use your
article to help me to include the Blowfish crypting in my project.
But it's VC6 project and as you advised I tried to work with the
code and copy it to my project. I did that but I'm always getting error,
when I try to use BlowFishEnc::encryptStream method:

error LNK2001: unresolved external symbol "public: virtual __thiscall BlowFishEnc::~BlowFishEnc(void)" (??1BlowFishEnc@@UAE@XZ)
error LNK2001: unresolved external symbol "public: virtual unsigned long __thiscall BlowFishEnc::encryptStream(char const *,unsigned long,char *)" (?encryptStream@BlowFishEnc@@UAEKPBDKPAD@Z)
error LNK2001: unresolved external symbol "public: __thiscall BlowFishEnc::BlowFishEnc(char const *)" (??0BlowFishEnc@@QAE@PBD@Z)



Could you, please, advise me what to do, as I'm a new in c++, I tried everything I know but it didn't work?

Here is how I tried to use the Blowfish:

***
I've have Blowfish.h, Blowfish.cpp, Encryption_I.h and sboxs.h in my project's
main directory.

In my CPP file, where I want to use the Blowfish crypting, I have: #include "Blowfish.h"

The function where I try to call the BlowFishEnc::encryptStream method is:


void CEncDecFileView::OnBtnEnc()
{
CIPHER _cipher;
_cipher = ENCRYPT_METHOD;

char _readFile[MAX_PATH];
char _writeFile[MAX_PATH];
char _password[100];
strcpy(_readFile, "c:\\a.txt");
strcpy(_writeFile, "c:\\b.txt");
strcpy(_password, "asdasd");

FILE *readFile = fopen(_readFile, "rb");
if (readFile == 0)
{
MessageBox("Unable to open source file (fopen).");
return;
}

const size_t bufferSize = 1024;
int barSize = 0;

// reaching the end of the file and getting position = getting file size (bytes).
fseek(readFile, 0, SEEK_END);
barSize = ftell(readFile);
fseek(readFile, 0, SEEK_SET);
if (barSize == -1)
{
MessageBox("Unable to get file size (_filelength).");
return;
}
barSize = barSize / bufferSize;


char outfile[MAX_PATH];
strcpy(outfile, _writeFile);

FILE *writeFile = fopen(outfile, "wb");
if (writeFile == 0)
{
MessageBox("Unable to open destination file.");
return;
}

char readBuffer[bufferSize];
char outBuffer[bufferSize];
size_t readRet = 0;

BlowFishEnc encryption(_password);

bool abort = false;
int encRet;
while (!feof(readFile))
{
readRet = fread(readBuffer, sizeof(char), bufferSize, readFile);
encRet = encryption.encryptStream(readBuffer, (DWORD)readRet, outBuffer);
fwrite(outBuffer, sizeof(char), encRet, writeFile);
}

fflush(writeFile);

fclose(writeFile);
fclose(readFile);

ZeroMemory(outBuffer, bufferSize);
ZeroMemory(readBuffer, bufferSize);
}

***

Can you help, please?

Thanks in advance!
Yasen
GeneralRe: VC6 Pin
Nir Dremer18-Apr-03 3:00
memberNir Dremer18-Apr-03 3:00 
GeneralHello... A request... Pin
lighttrainmedia11-Dec-02 5:54
memberlighttrainmedia11-Dec-02 5:54 
GeneralRe: Hello... A request... Pin
Nir Dremer13-Dec-02 0:02
memberNir Dremer13-Dec-02 0:02 
QuestionIs EFS not good enough? Pin
Andreas Saurwein Franci Gonçalves24-Sep-02 23:31
memberAndreas Saurwein Franci Gonçalves24-Sep-02 23:31 
AnswerRe: Is EFS not good enough? Pin
Nir Dremer25-Sep-02 0:08
memberNir Dremer25-Sep-02 0:08 
GeneralRe: Is EFS not good enough? Pin
Andreas Saurwein Franci Gonçalves11-Dec-02 6:10
memberAndreas Saurwein Franci Gonçalves11-Dec-02 6:10 
GeneralRe: Is EFS not good enough? Pin
Nir Dremer13-Dec-02 0:15
memberNir Dremer13-Dec-02 0:15 
GeneralRe: Is EFS not good enough? Pin
Andreas Saurwein Franci Gonçalves13-Dec-02 4:11
memberAndreas Saurwein Franci Gonçalves13-Dec-02 4:11 
GeneralRe: Is EFS not good enough? Pin
supersuper26-Apr-04 10:27
membersupersuper26-Apr-04 10:27 
GeneralRe: Is EFS not good enough? Pin
Andreas Saurwein Franci Gonçalves26-Apr-04 11:49
memberAndreas Saurwein Franci Gonçalves26-Apr-04 11:49 
GeneralRe: Is EFS not good enough? Pin
supersuper2-May-04 7:08
membersupersuper2-May-04 7:08 
AnswerRe: Is EFS not good enough? Pin
Anonymous1-Mar-04 0:33
memberAnonymous1-Mar-04 0:33 
GeneralRe: Is EFS not good enough? Pin
Andreas Saurwein Franci Gonçalves1-Mar-04 4:21
memberAndreas Saurwein Franci Gonçalves1-Mar-04 4:21 
GeneralBlowfish vs Twofish Pin
Anonymous23-Sep-02 12:06
memberAnonymous23-Sep-02 12:06 
GeneralRe: Blowfish vs Twofish Pin
Nir Dremer23-Sep-02 22:15
memberNir Dremer23-Sep-02 22:15 

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

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

Article
Posted 19 Sep 2002

Stats

250.3K views
12.7K downloads
88 bookmarked