我正在尝试使用OpenSSL libeay32.dll在Delphi中实现SHA256签名和验证.因此,在第一步中,我使用以下OpenSSL命令创建了一个RSA 2048位密钥对:
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -outform PEM -pubout -out public.pem
Run Code Online (Sandbox Code Playgroud)
那么容易.我做的下一步是创建一个能够从PEM文件中读取公钥和私钥的函数:
function TSignSHA256.ReadKeyFile( aFileName : String; aType : TKeyFileType ) : pEVP_PKEY;
var locFile : RawByteString;
locBIO : pBIO;
begin
locFile := UTF8Encode( aFileName );
locBIO := BIO_new( BIO_s_file() );
try
BIO_read_filename( locBIO, PAnsiChar(locFile) );
result := NIL;
case aType of
kfPrivate : result := PEM_read_bio_PrivateKey( locBIO, result, nil, nil );
kfPublic : result := PEM_read_bio_PUBKEY( locBIO, result, nil, nil );
end;
finally …Run Code Online (Sandbox Code Playgroud)