我需要一个组件或库(尽可能简单,没有DLL会很棒)加密文本,使用OpenSSL生成的公钥解密另一个文本。
我以为我会使用LockBox(新版本,v3),但据其他用户说,它不如旧版本好,更重要的是,不能使用其他库中的密钥。 (见OpenSSL's PEM file and Lockbox3 interoperability)
我正在使用Delphi 7.有什么建议吗?
答案 0 :(得分:6)
我们在Delphi 2010中使用Lockbox 2,效果很好。我想它也适用于Delphi 7.这是一个代码示例:
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包含一个演示应用,可让您生成公钥和私钥。
答案 1 :(得分:4)
我们SecureBlackbox将完成这项工作。支持Delphi 7。还支持PEM格式的证书和密钥(如果您在PEM中编码了原始RSA密钥,则需要编写几行代码来打开它,并且通过一个函数调用从PEM加载X.509证书)
答案 2 :(得分:3)
这是一本手册,如何将libeay32.dll从openssl导入delphi:
http://www.disi.unige.it/person/FerranteM/delphiopenssl/
他们使用RSA进行文件加密/解密:
http://www.disi.unige.it/person/FerranteM/delphiopenssl/RSAEncrypt.html