Solved

Encryption of data using Delphi

Posted on 1998-12-08
13
328 Views
Last Modified: 2010-04-04
Howdy

I'll get straight to the point.
For a program I'm making, I need to encrypt data which is stored in binary format in a file.

I know very little abouyt encrypting data in Delphi. Ciuld somebody PLEASE guide me as to how to go about doing something like this, or show me a site where i can learn!

Thanx
0
Comment
Question by:X_Kalibur
  • 6
  • 5
  • 2
13 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350021
Look at the Delphi Super Page (http://sunsite.icm.edu.pl/delphi/), there are a bunch of them there. Go to the search page and enter encryption for the search criteria.

Cheers,

Raymond.
0
 
LVL 2

Expert Comment

by:Thaddy
ID: 1350022
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1350023
rwilson:

Its not that your answer was wrong, but I didnt express what I wanted clearly..Sorry!

What I'm looking for, are just basic method of encryption, so that the file cant be hacked. I'm not really looking for hardcore algorithms to give me nightmares!
If you can help me, I'd really appreciate it!

thanx

- x
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 1350024
OK - a simple and effective algorithm for preventing someone hacking a file!

Step1. Take the file and calculate the crc32 checksum for it (there are crc32 sources left, right and center on the web - do an Altavista search and pick one that fits into your system best.)

Step2. XOR that 32 bit number with your phone number (or some other number)

Step3. Store that number with the file (perhaps at the beginning) or as a registry entry.

Step4. When you come to use the file calculate the CRC32 XO it with your number and check it against the previously calculated value - if its different the file has been tampered with.

Cheers,

Raymond.


0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1350025
Thanx.

Thats basically what i wanted to know... Are there any other ways of encrypting stuff, or do you just XOR it?
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350026
There are thousands of ways of doing it! Any method that alters information into unreadable form and can return it to its original condition could be called encryption (perhaps the oldest and best known is the Ceasar cipher where you rotate the letters of the alphabet by a number of chars (eg: a shift of 2 means a--> c, b--> d etc) Perhaps the newest and potentially strongest are called alliptic curve ciphers - though there is a current argument regarding their strength.

Compressing data is an effective form of encryption is sother parties do not know how to decompress it!

Basically you pick what suits your needs best.

Cheers,

Raymond.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:X_Kalibur
ID: 1350027
rwilson:

Is there a way, that I can directly XOR (or perform any other boolena operation) a string of text. Because I tried to directly XOR the string with a key, and it only likes integer values. So I "val"ed the string, and then XORed the val, and the result I got was my key! Could you possibly show me a way to change the string so that it looks reasonably encrypted (Other than a Caesars Cypher).
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350028
XOR each char individually eg:

Function XORit(Source, key : String) : String;
var,
  i : integer;

begin
  setlength(result, length(source));
  for I := 1 to length(source) do
    result[i] := chr(ord(source[i]) XOR ord(key[i mod length(key) + 1]));
end;

Cheers,

Raymond.  
0
 
LVL 2

Expert Comment

by:Thaddy
ID: 1350029
xor'ing is a very easy to break encryption algoritm. Anyone with two years math can do it.
I cannot reccommend xoring for any serious encryption, especially not if you use crc32 with it, since crc32 is designed to EASILY recreate an original file, because it can be used and was designed for fault tolerance.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350030
Thaddy: I agree, XORing is not a strong encryption, X_Kalibur was really looking for a simple means of making it hard for someone to modify a file. Hiding the actual contents didn't seem terribly important.

Cheers,

Raymond
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1350031
rwilson:

Actually, I'm sorry if I didnt make this clear before, but the whole idea of encrypting the file is so that it cant be read from any external viewer!

thanks

 -x
0
 
LVL 1

Author Comment

by:X_Kalibur
ID: 1350032
*Continued*

Are there other ways then to simply hide the contents?
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1350033
OK - let me make this clear:

You ARE hiding the contents of the file from an external viewer. The problem is that XORing is not a strong form of encryption (though, if the attacker cannot perform a chosen plaintext attack it can get pretty messy trying to break!)

As I mentioned in a previous comment there are thousands of ways to encrypt information. You need to decide why you are encrypting it --> This determines how much protection you require which will then push to towards certain classes of encryption methods.

Cheers,

Raymond.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now