Link to home
Start Free TrialLog in
Avatar of Ruan1618
Ruan1618

asked on

Crypto API

Hi,

I am looking for a simple Encrypt/Decrypt function to encrypt and decrypt a string in Delphi using some type of a key. I want to use a program to be able to encrypt a string on one computer and then using the same program on another computer I want decrypt it. I would like to use Crypto API and as far as I gathered all the Crypto API function sits in the Crypt32.dll?

The key will be hardcode in the EXE. The reason why I thought about using a key to encrypt/decrypt the data is because there should be no installation needed. I want to be able to send to EXE to person X and then he should be able to decrypt the data.

Can anyone help me find a suitable solution?
Avatar of dprochownik
dprochownik
Flag of Poland image

You can use LockBox components.

Simple sample:

uses
  LbCipher, LbString;

const
  cKey: TKey128 = (23,56,21,83,254,123,176,39, 239,2,19,47,146,192,234,152);

function Encrypt(const pInString: String): String;
begin
  result := BFEncryptStringEx(pInString,cKey,true);
end;

function Decrypt(const pInString: String;
                   var pOutString: String): Boolean;
begin
  try
    pOutString := BFEncryptStringEx(pInString,cKey,false);
    result := true;
  except
    result := false;
  end;
end;
LockBox components can be download from:
http://sourceforge.net/projects/tplockbox/

Unfortunatelly it was written for older delphi versions, so if you will have problems with installation on D2007 then I can give you my package :).
ASKER CERTIFIED SOLUTION
Avatar of MerijnB
MerijnB
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
Avatar of Ruan1618
Ruan1618

ASKER

Thanks for the reply! :) It was very useful all though the problem is that I need to implement this in C# as well as Delphi. The reason for this is that we would like to start using encryption in our current programs and we have programs in Delphi and C#. This is why I am looking for encryption methods that forms part of windows and not something that is included as part of our program. That is the reason why Im would like to use crypto32.dll. I have also found that advapi32.dll also contains encryption methods that can be used in Delphi and C#. So I am looking for good methods to use in crypto32.dll or advapi.dll that uses a public/private key or something similar.