Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

RSA.Sign

Signs data with RSA digital signature.

Component Version macOS Windows Linux Server iOS SDK
Sign Encryption 6.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "RSA.Sign"; Algorithm; InputType; InputData; InputEncoding; KeyType; KeyData; KeyEncoding; PasswordType; PasswordData; PasswordEncoding; OutputType; OutputInfo )   More

Parameters

Parameter Description Example
Algorithm Which algorithm to use. Can be MD4, MD5, SHA, SHA1, MDC2, RIPEMD160, SHA224, SHA256, SHA384 or SHA512. "SHA512"
InputType The type of input data.
Can be Text, Container, Image, Path, PDF, Data, base64 or Hex.
"Text"
InputData The actual input data.
Text, container or file path.
"Hello World"
InputEncoding The text encoding for text input.
Parameter is ignored for other cases.
"UTF-8"
KeyType The type of input for private key.
Can be Text, Container, Image, Path, PDF, Data, base64 or Hex.
"Path"
KeyData The actual input data for the key.
Text, container or file path. Must not be longer than the maximum key length of the given algorithm. If key is too short, we pad it with zero bytes.
"/Users/cs/desktop/test.pem"
KeyEncoding The text encoding for text input for the key.
Parameter is ignored for other cases.
PasswordType The type of input for the password of the private key.
Can be Text, Container, Image, Path, PDF, Data, base64 or Hex.
"Text"
PasswordData The actual input data for the password of the private key.
Text, container or file path. Must not be longer than the maximum key length of the given algorithm. If key is too short, we pad it with zero bytes.
"Hello World"
PasswordEncoding The text encoding for text input.
Parameter is ignored for other cases.
"UTF-8"
OutputType The output type.
Can be Base64, Hex, Text, File, Path.
Added Base64URL as option for plugin version 10.3.
"Hex"
OutputInfo The addition info for output.
For text it is the text encoding, for file container the file name and for path the actual native file path.
""

Result

Returns signature or error.

Description

Signs data with RSA digital signature.
Returns signature data in the format specified in OutputType.

Internally we make a hash of the data with given algorithm, open the private RSA key and do a RSA sign operation. We return the signature.

Optional you can pass a password to read password protected keys.

You pass data as triplet of type, data and encoding. For the types use:
Text: Pass text and encoding.
Data or File: Pass a container to read its content as data.
PDF: Pass a container containing a PDF document.
Container: Pass a container, which will be serialized.
Image: Pass a container containing an image, e.g. JPEG, TIFF, PNG, GIF, etc.
GIF: Pass a container containing a GIF document.
JPEG: Pass a container containing a JPEG document.
PNG: Pass a container containing a PNG document.
TIFF: Pass a container containing a TIFF document.
Path: Pass a file name as data. The file is read and it's content is used.
Hex: Pass a hex encoded value as text.
Hash: Pass the hex encoded hash to use instead of hashing data.

Examples

Sign data with private key file:

MBS( "RSA.Sign"; "SHA512";
"Text"; "Hello World. This is test data to sign."; "UTF8";
"Path";
"/Users/cs/Desktop/Sign and Verify/test.pem";
"UTF8";
"text"; ""; "";
"hex"; "" )

How to create keys and test in command line on macOS:

Create private key:

openssl genrsa -out test.pem 4096

Create public key:

openssl rsa -in test.pem -pubout -out test.pub

Sign datafile.txt:

openssl dgst -sha1 -sign test.pem -out signature.sha1 Create\ Keys.rtf

Verify signature

openssl dgst -sha1 -verify test.pub -signature signature.sha1 Create\ Keys.rtf

To encrypt the private key, use a command like this:

openssl genrsa -des3 -out test.pem 2048

Sign call with private key included as text:

MBS( "RSA.Sign"; "SHA512";
"Text"; "Hello World. This is test data to sign."; "UTF8";
"Text";
"-----BEGIN RSA PRIVATE KEY-----" & ¶ &
"MIIJKQIBAAKCAgEAz71qzCQEpcV4BbBl1+D0IKmjOy+gzxY8CqPAkZTzQhHw8UE9" & ¶ &
"KrnAjWm8Ze+9TNMs0Ar3ttJzLwnY4+12I5L9H0HTsW4hrzZI8kv0GtS98KJxAJ+x" & ¶ &
"7k6Om5N6ZQj/wgkBbR1PC+89k+IkVwvwQ9nLq9pLocEabvfeesIdEYqrpPc3K35O" & ¶ &
"T1hcPY3B5ISUmLC51S9yGvJdnp8+7GWpthCL46SVtl0VUZkEQGDWNquvnECJD99L" & ¶ &
"9TdWz0WV1SOksjNNzEYCotKtco27AoL4wNoZklAi0RbrfxPHZ8G2E9ZdDWmUkIKZ" & ¶ &
"aE5YYAAIu57ZIBW7E2UqczkhHi+qXnZ/wlH3mB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; "";
"hex"; "" )

Sign some text:

Set Field [Table::Signature; MBS( "RSA.Sign"; Table::Algorithm; "Text"; Table::Text to Sign; "UTF8"; "text"; Table::PrivateKey; "UTF8"; ""; ""; ""; "hex"; "" )]

Calculate JWT with RS256:

Let ( [
secret = "secretkey";
header = JWT RS256::Header;
payload = JWT RS256::Payload;
encodedString = MBS( "Text.EncodeToBase64URL"; header; "UTF-8" ) & "." & MBS( "Text.EncodeToBase64URL"; payload; "UTF-8" );

// calculate hash
hash = MBS( "RSA.Sign"; "SHA256";
"Text"; encodedString; "UTF-8";
"Text"; JWT RS256::Key; "UTF-8";
"text"; JWT RS256::Password; "UTF-8";
"base64url"; "");

// and built final result:
result = encodedString & "." & hash
]; result )

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

Created 12nd March 2016, last changed 15th April 2024


RSA.PublicEncrypt - RSA.Verify