RSA.PublicDecrypt
-----------------

Decrypts data using public key.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Encryption](component_Encryption.md) | [6.2](newinversion62.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "RSA.PublicDecrypt"; InputType; InputData; InputEncoding; KeyType; KeyData; KeyEncoding; OutputType { ; OutputInfo; PasswordType; PasswordData; PasswordEncoding; Padding } ) 

**MBS**( **"RSA.PublicDecrypt";** /\* Decrypts data using public key. \*/  
**$InputType**; /\* The type of input data.   
Can be Text, Container, Image, Path, PDF, Data, base64 or Hex.e.g. "Base64" \*/   
**$InputData**; /\* The actual input data.   
Text, container or file path.e.g. $EncryptedData \*/   
**$InputEncoding**; /\* The text encoding for text input.   
Parameter is ignored for other cases.e.g. "" \*/   
**$KeyType**; /\* The type of input for private key.   
Can be Text, Container, Image, Path, PDF, Data, base64 or Hex.e.g. "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.e.g. "/Users/cs/desktop/test.pem" \*/   
**$KeyEncoding**; /\* The text encoding for text input for the key.   
Parameter is ignored for other cases. \*/   
**$OutputType**; /\* The output type.   
Can be Base64, Hex, Text, File, Path.e.g. "Text" \*/   
**$OutputInfo**; /\* Optional; 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.e.g. "UTF-8" \*/   
**$PasswordType**; /\* Optional; The type of input for the password of the private key.   
Can be Text, Container, Image, Path, PDF, Data, base64 or Hex.e.g. "Text" \*/   
**$PasswordData**; /\* Optional; 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.e.g. "Hello World" \*/   
**$PasswordEncoding**; /\* Optional; The text encoding for text input.   
Parameter is ignored for other cases.e.g. "UTF-8" \*/   
**$Padding**) /\* Optional; Which padding to use.  
1: PKCS #1 v1.5 padding. This currently is the most widely used mode.  
2: PKCS #1 v1.5 padding with an SSL-specific modification that denotes that the server is SSL3 capable.  
3: Raw RSA encryption. This mode should only be used to implement cryptographically sound padding modes in the application code. Encrypting user data directly with RSA is insecure.  
4: EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty encoding parameter. This mode is recommended for all new applications.  
5: X931 padding.  
Default if not specified is 1.e.g. 1 \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| InputType | The type of input data.    Can be Text, Container, Image, Path, PDF, Data, base64 or Hex. | "Base64" |  |
| InputData | The actual input data.    Text, container or file path. | $EncryptedData |  |
| InputEncoding | The text encoding for text input.    Parameter is ignored for other cases. | "" |  |
| 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. |  |  |
| OutputType | The output type.    Can be Base64, Hex, Text, File, Path. | "Text" |  |
| 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. | "UTF-8" | Optional |
| PasswordType | The type of input for the password of the private key.    Can be Text, Container, Image, Path, PDF, Data, base64 or Hex. | "Text" | Optional |
| 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" | Optional |
| PasswordEncoding | The text encoding for text input.    Parameter is ignored for other cases. | "UTF-8" | Optional |
| Padding | Which padding to use.   1: PKCS #1 v1.5 padding. This currently is the most widely used mode.   2: PKCS #1 v1.5 padding with an SSL-specific modification that denotes that the server is SSL3 capable.   3: Raw RSA encryption. This mode should only be used to implement cryptographically sound padding modes in the application code. Encrypting user data directly with RSA is insecure.   4: EME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty encoding parameter. This mode is recommended for all new applications.   5: X931 padding.   Default if not specified is 1. | 1 | Optional |

### Result

Returns decrypted data or error.

### Description

Decrypts data using public key.  
Using RSA keys with any key size.  
Password is optional for decrypting encrypted keys.  
  
You can decrypt the data here after encrypting it with [RSA.PrivateEncrypt](RSAPrivateEncrypt.md).  
You can create a new private key using [RSA.GeneratePrivateKey](RSAGeneratePrivateKey.md) function. The [RSA.GetPublicKey](RSAGetPublicKey.md) function extracts the public key from a private key.  
  
Because of the nature of the RSA algorithm, a single encryption process can only encrypt input data that is smaller than the modulus value of the RSA key. In other words, the size (number of bytes) of the input data should be smaller than the size (number bytes) of the modulus, which is also the RSA key size.  
### Examples

Decrypt with public key:

 Set Variable \[$r ; Value:MBS ( "RSA.PublicDecrypt"; "base64"; RSA Public Private Encryption::EncryptedText ; ""; "Text"; RSA Public Private Encryption::PublicKey ; "UTF-8"; "Text"; "UTF-8")\]  
If \[MBS ("IsError")\]  
 Show Custom Dialog \["Error"; $r \]  
Else  
 Set Field \[RSA Public Private Encryption::DecryptedText ; $r \]  
End If  
### See also

- [IsError](IsError.md)
- [RSA.GeneratePrivateKey](RSAGeneratePrivateKey.md)
- [RSA.GetPublicKey](RSAGetPublicKey.md)
- [RSA.PrivateEncrypt](RSAPrivateEncrypt.md)
- [RSA.PublicEncrypt](RSAPublicEncrypt.md)

### Example Databases

- [Encryption and Hash/RSA Public Private Encryption](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/Encryption%20and%20Hash/RSA%20Public%20Private%20Encryption.shtml#4ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 6.2pr6](https://www.mbsplugins.de/archive/2016-04-29/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)

This function is free to use.

Created 21st April 2016 , last changed 21st May 2025

  
[RSA.PrivateEncrypt](RSAPrivateEncrypt.md) - [RSA.PublicEncrypt](RSAPublicEncrypt.md)

[HTML Version](RSAPublicDecrypt.shtml)