Upgrading from Delphi 2005 to 2010 libeay32.dll
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;
begi开发者_运维问答n
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
You should get a warning W1044 "Suspicious typecast of TFileName to PAnsiChar".
You're typecasting TFileName
(which is an alias for string
and in Delphi 2010 this is UnicodeString
) directly to PAnsiChar
.
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:
BIO_read_filename(keyfile, PAnsiChar(UTF8Encode(AFileName)));
精彩评论