Root > Reference > All Functions > RSASign

Function RSASign

Previous pageReturn to chapter overviewNext page   

Signs data.

 

Unit

EEncrypt

 

Syntax

 

Code (Delphi)

function RSASign(

const AKey: TRSAKey;

const AData: Pointer;

const ADataSize: Cardinal

): TRSASignature; overload;

 

function RSASign(

const AKey: TRSAKey;

const AData: TEncryptBuffer

): TRSASignature; overload;

 

function RSASign(

const AKey: TRSAKey;

const AData: RawByteString

): TRSASignature; overload;

 

Parameters

AKey [in]

A key for digital signing. Comes from RSAGenKey function or RSALoadPrivateKey function. A private key will be used.

 

AData [in]

Data to be signed.

 

ADataSize [in]

Size of AData in bytes.

 

Return value

Digital signature (little-endian). Release it with SecureFree function.

 

Remarks

This function digitally signs the specified data and returns digital signature. Digital signature is a small RAW bytes value, which can be freely copied and/or exported/imported.

 

Your private key will be used for digital signing.

 

You can verify the returned signature with RSAVerify function.

 

Note

Internally RSASign will calculate SHA-1 hash of AData and sign (encrypt) resulting hash with RSA and private key. EMSA-PKCS1-v1_5 scheme is used for padding.

 

Important!

The resulting signature bytes are in little-endian order. You must reverse bytes order if you want to verify this signature with other tools which requires big-endian order (such as .NET or OpenSSL).

 

Examples

 

Code (Delphi)

var

// Key to sign data

RSAKey: TRSAKey;

// Data to sign

S: String;

// Digital signature for S

Signature: TRSASignature;

begin

// Load private key

RSAKey := RSALoadPrivateKey('C:\Private.pem', rsText, 'Private key password (if any set)');

try

 

// Data to sign

S := 'Some data';

 

// Sign data

Signature := RSASign(RSAKey, Pointer(S), Length(S) * SizeOf(Char));

try

// Clear key as soon as possible

RSADestroyKey(RSAKey);

 

// Store signature somewhere

edSignature.Text := HexEncodeToString(Signature.pbData, Signature.cbData);

 

finally

// Free signature once we finished working with it

SecureFree(Signature);

end;

finally

RSADestroyKey(RSAKey);

end;

end;

 

See also




Send feedback... Build date: 2024-09-30
Last edited: 2024-09-30
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_rsasign.php