Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to I encrypt my INI file?

2 views
Skip to first unread message

Hans Fandsen

unread,
Dec 5, 2000, 3:00:00 AM12/5/00
to
I'm using standard Delphi TIniFile. Is there a way to encrypt the final INI
file somehow and decrypt it when reading it again.
Or should I just use a form of CRC to validate the ini file.

I want to achive that people don't use my program by just re-editing the
inifile and not by using my program. This is also to protect against piracy.

Hans

Cristian Nicola

unread,
Dec 5, 2000, 3:00:00 AM12/5/00
to
Check out TCryptIni (commercial but you can buy the sources for something
like $50).
Alternatively you can use some tricks like a string list accessing text to
crypt/decrypt using a standard algorithm and then save/load from file.
You have value of, but it will take some time to write the [] section part.
About crc, send me an e-mail if you want crc routines.
Regards,
Cristian Nicola

Hans Fandsen

unread,
Dec 5, 2000, 3:00:00 AM12/5/00
to
Thanks Cristian,

Looks like the guy that made TCryptIni just added crypting of the values and
not the keys. I wanted to encrypt every bit of the ini file. Totally
unreadable.

But hiss way will also do the trick. Noone will be able to pirate the
program with a notepad.

I don't want to pay $50 for something this basic, so I will just make my own
TCryptIni inherited from TIniFile. The encrypting doesn't need to be like
1024 bit or something like that, just hard enough so that a notepad won't do
the trick.

About the CRC routines, I'm always interrested in learning new stuff, so
bring it on :)

Thanks!
Hans

"Cristian Nicola" <wh...@dahas.ro> wrote in message
news:90jjas$h9...@bornews.inprise.com...

Earl F. Glynn

unread,
Dec 5, 2000, 3:00:00 AM12/5/00
to
"Hans Fandsen" <ultra...@usa.net> wrote in message news:3a2d5442_2@dnews...

> I don't want to pay $50 for something this basic, so I will just make my own
> TCryptIni inherited from TIniFile. The encrypting doesn't need to be like
> 1024 bit or something like that, just hard enough so that a notepad won't do
> the trick.

For a simple approach, look at the algorithm used here:
http://www.efg2.com/Lab/ImageProcessing/CryptImage.htm

For a variety of other approaches:
http://www.efg2.com/Lab/Library/Delphi/MathFunctions/Cryptography.htm

> About the CRC routines, I'm always interrested in learning new stuff, so
> bring it on :)

After closing the INI file, one simple approach might be to CRC the whole
file (excluding any CRC line). Then re-open the INI file and insert a
CRC value. Later, you could re-CRC the whole file (ignoring the CRC
line that you inserted). If someone tampers with the file, the CRC will
change. If someone tampers with the CRC value, the computed
CRC from the file won't match. The "average" person won't know
how to modify the file and the CRC to match. This will at least
keep "honest people" honest.

Here's some CRC info:
http://www.efg2.com/Lab/Mathematics/CRC.htm
http://www.efg2.com/Lab/Mathematics/FileCheck.htm

--
efg

Earl F. Glynn E-mail: ef...@efg2.com
Overland Park, KS USA

efg's Computer Lab: http://www.efg2.com/Lab
Mirror: http://homepages.borland.com/efg2lab/Default.htm

Rene Tschaggelar

unread,
Dec 5, 2000, 3:00:00 AM12/5/00
to
The point of ini files is that they are readable and editable.
If you don't want this feature, save your stuff as binary.

Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com

Hans Fandsen

unread,
Dec 5, 2000, 3:00:00 AM12/5/00
to
How do you mean as binary?

The idea of using ini file is that it is easy to use the component provided.
But if you have a better way, I would be greatful

Hans

"Rene Tschaggelar" <tscha...@dplanet.ch> wrote in message
news:3A2D6BAF...@dplanet.ch...

Breyten Ernsting

unread,
Dec 5, 2000, 3:00:00 AM12/5/00
to
ultra...@usa.net (Hans Fandsen) wrote in <3a2d5442_2@dnews>:

>Thanks Cristian,
>
>Looks like the guy that made TCryptIni just added crypting of the values
>and not the keys. I wanted to encrypt every bit of the ini file. Totally
>unreadable.

So basically you want to do this :
reading :
- uncrypt the (crypted).ini file to a temp. file
- use the normal routines to read the values in that file
(- delete the temp file)
writing:
(- create the temp file)
- crypt the temp file to the crypted .ini file
- delete the temp file

With this approach you can just use any component that allows complete file
encryption.

Breyten

--
Breyten J. Ernsting (ICQ: 1760075) http://www.bje.nu/
"Ga nooit naar de avondwinkel als je teveel hebt geblowt!"
Firma Onkruid - Snack

Gary Darby

unread,
Dec 5, 2000, 3:00:00 AM12/5/00
to
Pretty straightforward if what you are saving is just some strings,
integers, etc. and if you can set maximum lengths for any strings. Just
define a record... well something like this

TParamrec=record
fontcolor:TColor;
maxsize:integer;
formcaption:string[50];
{etc}
end;

...
params:TParamrec;
f:file of TParamrec;
....
{save file}
with params do
begin
fontcolor:=font.color;
formcaption:=caption;
maxsize:=strtoint(edit1.text);
{etc}
end;
assignfile(f,extractfilepath(application.exename)+'Params');
rewrite(f);
write(f,params);
closefile(f);

Load is logical inverse of this. If file doesn't exist at load time, you
can initialize with default values. Load and Save can be in Initialization
and Finalization sections respectively.

_________________________
Gary
http://www.delphiforfun.org
_________________________


"Hans Fandsen" <ultra...@usa.net> wrote in message

news:3a2d6cff_1@dnews...

Paul Moorcroft

unread,
Dec 5, 2000, 9:07:26 PM12/5/00
to
Have you thought about using the TMemIniFile component It work just like the
TIniFile but it reads the file in in one go into memory and the best thing
is that you can supply the actual Ini file in a TStringList object. You
could do something like the following :


Ini := TMemIniFile.Create(''); // don't supply a file name to load, is
empty.

// put the code to read in your encrypted file and convert to a standard
INI in a TStringList object.

Ini.SetStrings(DecryptedStringList);

// Now use the Ini object to read and write your values.

// .....

// At the end.
Ini.GetStrings(ToBeEncryptedStringList);

// put the code to encrypt the TStringList and save to a file.

Ini.Free;

Paul Moorcroft

Rene Tschaggelar

unread,
Dec 6, 2000, 3:00:00 AM12/6/00
to
The ini file contains some values together with an identifier,
divided into groups.
The groups are independent of the location and the items in a group are
independent of the location within the group.

If the location has to independent, a crypted ini file is propably the best.
If the location can be fixed (lacking updateability of the app) just
write the values in series as binary.

Rene
--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com

Martin Cremer

unread,
Dec 7, 2000, 2:35:43 AM12/7/00
to
See below,

this should work for you.

procedure NewOrientation(FHandle: HDC; NewOrientation: Byte);
var
ActPrinter : String;
DevMode : PDeviceMode;
SubDevMode : TDeviceMode;
PrinterH : THandle;
DeviceMode : THandle;
begin
ActPrinter := Printer.Printers[Printer.PrinterIndex];
If Pos('an',ActPrinter) <> 0 then
Delete(ActPrinter,Pos('an',ActPrinter)-1,Length (ActPrinter)) else if
Pos('on',ActPrinter) <> 0 then
Delete(ActPrinter,Pos('on',ActPrinter)-1,Length(ActPrinter));
OpenPrinter(PChar(ActPrinter),PrinterH,nil);
DeviceMode := GlobalAlloc(GHND,DocumentProperties(0, PrinterH,
PChar(ActPrinter), SubDevMode, SubDevMode, 0));
if DeviceMode <> 0 then
begin
DevMode := GlobalLock(DeviceMode);
DocumentProperties(0, PrinterH, PChar(ActPrinter), DevMode^,
DevMode^, DM_OUT_BUFFER);
case NewOrientation of
0: DevMode.dmOrientation := DMORIENT_PORTRAIT;
1: DevMode.dmOrientation := DMORIENT_LANDSCAPE;
end;
DevMode.dmFields := DevMode.dmFields or DevMode.dmOrientation;
if EndPage(FHandle) <= 0 then
ShowMessage('error');
ResetDC(FHandle,DevMode^);
GlobalUnlock(DeviceMode);
GlobalFree(DeviceMode);
end;
end;

procedure StartPrinting;
begin
Printer.Orientation := poPortrait;
Printer.BeginDoc;
Printer.Canvas.TextOut(0,0,'Hello world...');
NewOrientation(Printer.Handle,1); // Printer.Orientation :=
poLandscape;
Printer.NewPage;
Printer.Canvas.TextOut(0,25,'Hello world...');
end;

Good luck.

Cheers

Martin Cremer
----- Original Message -----

From: EJP
Newsgroups: borland.public.delphi.vcl.components.using
Sent: Tuesday, December 05, 2000 7:43 PM
Subject: Any way to change Printer.Orientation mid job?


I'm looking for a way to change the orientation of a single page in a
multipage
print job without having to print it as a separate document.
Printer.Orientation
can't be changed while printing.

TIA,

Jay

0 new messages