从 Delphi 2005 升级到 2010 libeay32.dll
我正在将我的程序从 Delphi 2005 升级到 Delphi 2010。 我在使用 RSA 函数时遇到问题
以下过程在 D2005 下运行良好,但在 D2010 下结果始终为零。 我已经尝试过新版本的 libeay32.dll
function ReadPrivateKey(AFileName: TFileName): pEVP_PKEY;
var
keyfile: pBIO;
a : pEVP_PKEY;
begin
a := nil;
keyfile := BIO_new(BIO_s_file());
BIO_read_filename(keyfile, PAnsiChar(AFilename));
result := PEM_read_bio_PrivateKey(keyfile, a, nil, nil);
if result = nil then
begin
raise Exception.Create('Não foi possível ler a chave privada.');
end;
BIO_free(keyfile);
end;
有人遇到这个问题吗? 谢谢 山姆
I'm upgrading my program from Delphi 2005 to Delphi 2010.
I'm having a problem with RSA functions
The following procedure work's well under D2005, but with D2010 the result is always nil.
I allready tried with new version of libeay32.dll
function ReadPrivateKey(AFileName: TFileName): pEVP_PKEY;
var
keyfile: pBIO;
a : pEVP_PKEY;
begin
a := nil;
keyfile := BIO_new(BIO_s_file());
BIO_read_filename(keyfile, PAnsiChar(AFilename));
result := PEM_read_bio_PrivateKey(keyfile, a, nil, nil);
if result = nil then
begin
raise Exception.Create('Não foi possível ler a chave privada.');
end;
BIO_free(keyfile);
end;
Does anyone had this problem?
Thanks
Sam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该收到警告 W1044“TFileName 到 PAnsiChar 的可疑类型转换”。
您正在将
TFileName
(这是string
的别名,在 Delphi 2010 中为UnicodeString
)直接转换为PAnsiChar
。我猜
BIO_read_filename
已经失败了;您不检查返回值。根据 文档,它需要 UTF8 编码的字符串,因此请尝试使用UTF8Encode:You should get a warning W1044 "Suspicious typecast of TFileName to PAnsiChar".
You're typecasting
TFileName
(which is an alias forstring
and in Delphi 2010 this isUnicodeString
) directly toPAnsiChar
.I guess that already
BIO_read_filename
fails; you don't check the returned value. According to the documentation, it expects UTF8-encoded string, so try encoding it with UTF8Encode: