I need a component or library (as simple as possible, and no DLLs would be great) to encrypt a text, decrypt another, using public keys generated by OpenSSL.
I thought I'd use LockBox (the new version, v3), but according to other users here it's not as good as the old version, and more importantly, cannot use keys from other libraries. (see OpenSSL's PEM file and Lockbox3 interoperability)
I'm using Delphi 7. Any suggestions?
We use Lockbox 2 in Delphi 2010 and it works great. I guess it should also work with Delphi 7. Here's a code sample:
unit LBRSA;
interface
uses
LbCipher,
LbRSA,
LbString,
LbUtils;
function DecryptRSA(const CipherText: String): String; overload; overload;
function DecryptRSA(const CipherText, Exponent, Modulus: String): String; overload;
implemention
function EncryptRSA(const ClearText, Exponent, Modulus: String): String;
var
RSA: TLbRSA;
begin
RSA := TLbRSA.Create(nil);
try
RSA.PublicKey.ExponentAsString := Exponent;
RSA.PublicKey.ModulusAsString := Modulus;
Result := RSA.EncryptStringW(ClearText);
finally
FreeAndNil(RSA);
end;
end;
function DecryptRSA(const CipherText, Exponent, Modulus: String): String;
var
RSA: TLbRSA;
begin
RSA := TLbRSA.Create(nil);
try
RSA.PrivateKey.ExponentAsString := Exponent;
RSA.PrivateKey.ModulusAsString := Modulus;
Result := RSA.DecryptStringW(CipherText);
finally
FreeAndNil(RSA);
end;
end;
end.
Lockbox includes a demo app that lets you generate the public and private keys.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With