RSA.PrivateEncrypt
------------------

Encrypts data using private key.

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

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

**MBS**( **"RSA.PrivateEncrypt";** /\* Encrypts data using private key. \*/  
**$InputType**; /\* The type of input data.   
Can be Text, Container, Image, Path, PDF, Data, base64 or Hex.e.g. "Text" \*/   
**$InputData**; /\* The actual input data.   
Text, container or file path.e.g. "Hello World" \*/   
**$InputEncoding**; /\* The text encoding for text input.   
Parameter is ignored for other cases.e.g. "UTF-8" \*/   
**$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. "Hex" \*/   
**$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. "" \*/   
**$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. | "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. |  |  |
| OutputType | The output type.    Can be Base64, Hex, Text, File, Path. | "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. | "" | 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 encrypted data or error.

### Description

Encrypts data using private key.  
Using RSA keys with any key size.  
Password is optional for decrypting encrypted keys.  
  
You can encrypt the data here and later decrypt with [RSA.PublicDecrypt](RSAPublicDecrypt.md).  
You can create a new private key using [RSA.GeneratePrivateKey](RSAGeneratePrivateKey.md) function.  
### Examples

Encrypt with private key:

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

- [IsError](IsError.md)
- [RSA.GeneratePrivateKey](RSAGeneratePrivateKey.md)
- [RSA.PrivateDecrypt](RSAPrivateDecrypt.md)
- [RSA.PublicDecrypt](RSAPublicDecrypt.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#1ScriptAnchor_)

### 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 30th May 2016

  
[RSA.PrivateDecrypt](RSAPrivateDecrypt.md) - [RSA.PublicDecrypt](RSAPublicDecrypt.md)

[HTML Version](RSAPrivateEncrypt.shtml)