![]() |
Multimedia »
General Graphics »
Bitmaps
Intermediate
License: The Code Project Open License (CPOL)
A very simple solution for partial bitmap encryptionBy Jim XochellisA simple and fast image encryption technique, which facilitates the secure use of external image files in common applications. |
VC7.1Win2K, WinXP, MFC, VS.NET2003, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||

It can often be preferable for developers to store application images in separate image files, because it makes the construction and the maintenance of the application considerably easier. For example, using external images usually facilitates the cooperation between the programmer and the GUI designer, accommodates the localization and the use of themes, and also makes the updating procedure easier and faster.
On the other hand, having separate image files makes it easier for unauthorized persons, to change the appearance of the application, which is often unacceptable. Someone could add here that, in the case of the external image files, there is also a danger of stealing the GUI images. In my opinion, this is not an important issue (at least, not for still images), since these images are going to be displayed on the screen eventually, and screen captures are very easy to do. Hence, stealing the GUI images can almost never be avoided.
The most obvious solution in order to use external images and also avoid the dangers described above, is to encrypt the image data. However, encryption will introduce two new problems to the image loading procedure. It will make this procedure much more complicated and slower. Since loading speed and simplicity are very important issues in my case, I have made the following design decisions:
N consecutive pixel rows of every image will be encrypted, the next M pixel rows will not be encrypted, and then again the next N pixel rows will be encrypted etc. The actual values of N and M will be user defined.
As a result of the above design decisions, the encrypted image will be easily recognizable (only some pixel rows will be encrypted), but it would be difficult to reuse it in another application, and even more difficult to replace or modify it in an existing application.
All my implementation code resides in the CImgCrypt class, which is derived from the CBlowFish class, introduced by George Anescu in another CodeProject article [1]. Compared to the CBlowFish class, CImgCrypt provides two additional public methods that can be used in order to encrypt and decrypt DIB Sections.
bool CImgCrypt::EncryptDIBSection(HBITMAP hbitmap, unsigned encryptedHeight, unsigned unencryptedHeight) bool CImgCrypt::DecryptDIBSection(HBITMAP hbitmap, unsigned encryptedHeight, unsigned unencryptedHeight)
Specifically, the CImgCrypt::EncryptDIBSection and CImgCrypt::DecryptDIBSection methods encrypt or decrypt, respectively, the DIB Sections that correspond to their hbitmap parameter, processing encryptedHeight pixel rows, and skipping unencryptedHeight pixel rows by turns. Both these methods return true on success, and false otherwise. As a simple usage example, I demonstrate below, a piece of code that loads and decrypts a BMP file:
CImgCrypt imgCryptEngine("blowfish-key", 12); HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "image.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); imgCryptEngine.DecryptDIBSection(hBitmap, 3, 6);
I hope that this work will be helpful for you. In the download section, you will also find a demo application that provides a more "live" demonstration of what I have described in this article. Thank you for reading this.
I have based this work on the BlowFish implementation of George Anescu [1], and I have also used the CDIBSectionLite class of Chris Maunder [3] in my demo application. Thanks a lot guys!
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 15 Mar 2006 Editor: Smitha Vijayan |
Copyright 2006 by Jim Xochellis Everything else Copyright © CodeProject, 1999-2009 Web15 | Advertise on the Code Project |