Root > Reference > All Functions > RSAVerify

Function RSAVerify

Previous pageReturn to chapter overviewNext page   

Verifies digital signature.

 

Unit

EEncrypt

 

Syntax

 

Code (Delphi)

function RSAVerify(

const AKey: TRSAKey;

const AData: Pointer;

const ADataSize: Cardinal;

const ASignature: Pointer;

const ASignatureSize: Cardinal

): Boolean; overload;

 

function RSAVerify(

const AKey: TRSAKey;

const AData: TEncryptBuffer;

const ASignature: TRSASignature

): Boolean; overload;

 

function RSAVerify(

const AKey: TRSAKey;

const AData: RawByteString;

const ASignature: TRSASignature

): Boolean; overload;

 

Parameters

AKey [in]

A key for verification. Comes from RSAGenKey function or RSALoadPublicKey function. Must match the key used in RSASign function to sign AData. A public key will be used.

 

AData [in]

Data to be verified (the same data as the one passed to RSASign function). Must be unmodified (otherwise function will return False).

 

ADataSize [in]

Size of AData in bytes.

 

ASignature [in]

Signature to be verified (the same signature as the one returned by RSASign function). Little-endian.

 

ASignatureSize [in]

Size of ASignature in bytes.

 

Return value

True - if digital signature is OK, False - if digital signature is broken (i.e. AData is not the same/was changed; or wrong key is used).

 

Remarks

This function verifies digital signature created by RSASign function.

 

Your public key will be used for verification.

 

Important!

The signature bytes must be in little-endian order. You must reverse bytes order (before calling RSAVerify) if you want to verify signature generated by other tools which produce big-endian order signatures (such as .NET or OpenSSL).

 

Examples

 

Code (Delphi)

var

// Key to verify

RSAKey: TRSAKey;

// Data to verify

S: String;

// Digital signature for S

Signature: TRSASignature;

// If signature is broken or not

SignatureOK: Boolean;

begin

// Load public key

RSAKey := RSALoadPublicKey('C:\Public.pem', rsText);

try

 

// Data to verify

// (same as in RSASign example)

S := 'Some data';

 

// Load signature

Signature.cbData := HexCalcDecodedSize(Length(edSignature.Text));

Signature.pbData := AllocMem(Signature.cbData);

try

Base64DecodeFromString(edSignature.Text, Signature.pbData);

 

// Verify signature

SignatureOK := RSAVerify(RSAKey, Pointer(S), Length(S) * SizeOf(Char), Signature.pbData^, Signature.cbData);

 

// Clear key as soon as possible

RSADestroyKey(RSAKey);

 

if SignatureOK then

 // OK for S = 'Some data'

 Application.MessageBox('OK', 'Signature verification', MB_OK)

else

 // FAIL for any other S

 Application.MessageBox('FAIL', 'Signature verification', MB_OK or MB_ICONSTOP);

 

finally

SecureFree(Signature);

end;

finally

RSADestroyKey(RSAKey);

end;

end;

 

See also




Send feedback... Build date: 2024-12-11
Last edited: 2024-12-11
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/topic_function_eencrypt_rsaverify.php