开发者

Encrypt/ Decrypt text file in Delphi?

Hi i would like to know best encryption technique for text file encryption and ecr开发者_StackOverflowyption.

My Scenario:

I have software having two type of users Administartor and Operators. Our requirement is to encrypt text file when Administrator enter data using GUI and save it. That encrypted file would be input for Operator and they just need to select it and use that file. Here file should be automatically decrypt data for further calculation when Operator select those files.

Please help me which encryption/ decryption technique should i use?


A golden rule when doing crypto is to understand that cryptography as a whole it is very difficult.

There are a multitude of different approaches/algorithms to choose from, and no single algorithm/method can be said to be the best one. It all depends on your needs and possibilities to affect application distribution etc.

An example of a potentially problematic situation is that in your scenario the decryption "key" needs to be distributed with the application(s) and might make it insecure. This is generally referred to as the "Key Distribution" problem.

A good place to start reading about crypto is http://en.wikipedia.org/wiki/Cryptography.

As for ready made stuff for Delphi there are a few good packages available:

  • DEC v5.2 - http://blog.digivendo.com/2008/11/delphi-encryption-compendium-dec-52-for-d2009-released/
  • DCPCrypt - http://www.cityinthesky.co.uk/cryptography.html

Torry's pages also has a long list of components:

  • http://www.torry.net/pages.php?id=519
  • http://www.torry.net/pages.php?id=312

I strongly recommend you use some of the existing implementations and not start to do your own, since creating a secure working crypto algo is very very difficult.


When moving an encryptet message from place/appliction to another, one of the problems you have to consider is where to store the encryption/decryption keys.

As i se your scenario, it seems like it is build in your applications. If so remember to use al sorts of tricks to hide it: Password strings should be split in several bits and onlys appended in a protected memoryspace, that has to be marked as non-pageable (else password could be seen in the pagefile).
The same rules for the content that is unencrypted (the text-file). It's best that it never is saved (even temporaly) unencrypted to disk. If it is saved, the overwrite the date with garbage after use, before deleting it.

Another approch (specialy if you already use compression components), is that the (text) file, can be compressed using a password.


Truthfully, there is no "best" technique. It basically depends on the sensitivity of the data you're trying to protect and the number of people who might access this data. What might be "best" for me might be pure overkill for your project. In your case, you could use any dual-key encryption method. Or asymmetric key. Basically, the administrator has one key and the operator has the other. The administrator can then encrypt files, but he won't be able to decrypt them again, unless he has an operator key. The operator can decrypt the file and -if need be- encrypt a file that only an administrator can access. (Asymmetrical keys encrypt in both ways.)

There are several solutions that make use of these asymmetrical keys. The one that would be best is the one that you could add to your project in the easiest way while still offering enough protection for your needs.

Building your own asymmetrical key algorithm is possible too, if you're a real Math Wizard. The calculations are complex and involve extremely high prime numbers in most solutions. As K. Sandell said, find a good, existing solution that matches your needs in the best way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜