uses
SysUtils,
Classes,
openssl;
const
//LIBCRYPTO = 'libcrypto.dll';
//LIBCRYPTO = 'libcrypto-1_1-x64.dll';
LIBCRYPTO = 'libcrypto-3-x64.dll';
function RSA_verify(typ:integer; m: PByte; m_length: cardinal; sigbuf: PByte; siglen: cardinal; rsa: PRSA): integer; cdecl; external LIBCRYPTO;
function loadpub(path: string): PRSA;
var
bio: PBIO;
evp: PEVP_PKEY;
begin
result := nil;
bio := BIO_new_file(@path[1], 'r');
if bio = nil then exit;
evp := nil;
//evp := EvpPkeyNew;
result := PEM_read_bio_PUBKEY(bio, evp, nil, nil);
end;
var
r: integer;
message, signature: string;
rsa: PRSA;
f: PRSA_METHOD;
begin
//if not InitSSLInterface then begin
//if not InitSSLInterface('libssl.dll', 'libcrypto.dll') then begin
//if not InitSSLInterface('libssl-1_1-x64.dll', 'libcrypto-1_1-x64.dll') then begin
if not InitSSLInterface('libssl-3-x64.dll', 'libcrypto-3-x64.dll') then begin
writeln('init ssl failed');
readln;
halt;
end;
message := 'message';
signature := 'signature';
//rsa := loadpub('public_key.pem');
rsa := loadpub('public_key_sign.pem');
writeln('rsa = ', inttohex(ptrint(rsa)));
try
// Access violation reading from address $0000000000000060.
f := RSA_get_method(rsa);
r := f^.rsa_verify(672{NID_sha256}, @message[1], length(message), @signature[1], length(signature), rsa);
// Access violation reading from address $0000000000000060.
//r := RSA_verify(672{NID_sha256}, @message[1], length(message), @signature[1], length(signature), rsa);
except
on E: Exception do writeln(e.Message);
end;
readln;
end.