Link to home
Start Free TrialLog in
Avatar of Wim ten Brink
Wim ten BrinkFlag for Netherlands

asked on

A quicky...

CryptProtectData and CryptUnprotectData... (WinCrypt.h) How to use these API calls with Delphi?

Just a working example, please... I am using Windows 2000 or better only for this.

Or maybe a better suggestion to use instead. I need to keep my final code small and I need to encrypt&decrypt a single line in a configuration file. (Yes, it's a password.) So basically I need to get a plaintext, convert it to cyphertext and write it to the file. Later I need to read it again and convert it back to plaintext.
And yes, a strong encryption method is required. And it can't be a Delphi component since my little project doesn't even use the VCL.

Personally, I prefer to use the Windows API in this case.
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

ASKER

Increased the points. But in return I only accept a working example of the use of CryptProtectData AND CryptUnprotectData for encrypting a splaintext to cyphertext and back again!
Why do you need to convert it back to plaintext?

Mu suggestion would be to use a MD5 one-way hash.
No decrypting that one, that's for sure...
The application has two parts. An interactive one where the user can enter a password which is then stored in a configuration file, and an unattended part where the application reads the password from the configuration file and uses it for a secure connection to another system.
The interactive part is only used when the application is first used or when the password changes. (About once per month.) The unattended part is started at least once per day to connect to an FTP server and exchange a bunch of files. (Okay, simplified explanation since it's even more complex than this.)
Since no anonymous FTP connections are allowed, I need to store username and password. And to prevent someone with access to this system to discover the password, it needs to be encrypted.

I am trying to keep the size of this executable as small as possible so I limit myself to the WINAPI and the SysUtils unit. The application has one dialog resource inside it (not a form!) which allows the user to enter username and password if they start the app with a special command-line parameter. Since Windows has a nice encryption API I would like to make some good use of it.
Of course, other encryption methods could also be used but this spoils my challenge of keeping the whole thing below 75 KB... :-) Besides, who needs third-party components when the OS already provides me the service I need?
ASKER CERTIFIED SOLUTION
Avatar of Wim ten Brink
Wim ten Brink
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
no probs here...
Avatar of DelphiBasics
DelphiBasics

what units did you use to declare the blob structure and the cryptoprotect and unprotect functions.
thank you.

if i need to create a new question to ask this question then please post!
thanks :)