The*_*bie 5 delphi cryptography rsa
我需要一个组件或库(尽可能简单,没有DLL会很好)加密文本,使用OpenSSL生成的公钥解密另一个文本.
我以为我会使用LockBox(新版本,v3),但据其他用户说,它不如旧版本好,更重要的是,不能使用其他库中的密钥.(参见OpenSSL的PEM文件和Lockbox3互操作性)
我正在使用Delphi 7.有什么建议吗?
我们在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.
Run Code Online (Sandbox Code Playgroud)
Lockbox包含一个演示应用程序,可让您生成公钥和私钥.
这是一个手册,如何将 libeay32.dll 从 openssl 导入到 delphi 中:
http://www.disi.unige.it/person/FerranteM/delphiopenssl/
他们使用 RSA 进行文件加密/解密:
http://www.disi.unige.it/person/FerranteM/delphiopenssl/RSAEncrypt.html
归档时间: |
|
查看次数: |
4445 次 |
最近记录: |