RSA.EncryptPrivateKey
---------------------

Encrypts a private key.

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

MBS( "RSA.EncryptPrivateKey"; KeyType; KeyData; KeyEncoding; Algorithm; PasswordType; PasswordData { ; PasswordEncoding } ) 

**MBS**( **"RSA.EncryptPrivateKey";** /\* Encrypts a private key. \*/  
**$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. \*/   
**$Algorithm**; /\* Which algorithm to use. Can be for example RC2, blowfish, AES128, AES192, AES256. See [Encryption.Cipher](EncryptionCipher.md).e.g. "AES-128-CFB" \*/   
**$PasswordType**; /\* The type of input for optional password.   
Can be Text, Container, Image, Path, PDF, Data, base64 or Hex.e.g. "Text" \*/   
**$PasswordData**; /\* The actual input data for the password.   
Text, container or file path.e.g. "Hello World" \*/   
**$PasswordEncoding**) /\* Optional; The text encoding for text input.   
Parameter is ignored for other cases.e.g. "UTF-8" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| 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. |  |  |
| Algorithm | Which algorithm to use. Can be for example RC2, blowfish, AES128, AES192, AES256. See [Encryption.Cipher](EncryptionCipher.md). | "AES-128-CFB" |  |
| PasswordType | The type of input for optional password.    Can be Text, Container, Image, Path, PDF, Data, base64 or Hex. | "Text" |  |
| PasswordData | The actual input data for the password.    Text, container or file path. | "Hello World" |  |
| PasswordEncoding | The text encoding for text input.    Parameter is ignored for other cases. | "UTF-8" | Optional |

### Result

Returns key as text or error.

### Description

Encrypts a private key.  
Returns error if key could not be read, e.g. because it is already encrypted.  
### Examples

Encrypt private key and decrypt it:

 Set Variable \[ $key1 ; Value: MBS ( "[RSA.GeneratePrivateKey](RSAGeneratePrivateKey.md)") \]   
Set Variable \[ $key2 ; Value: MBS ( "RSA.EncryptPrivateKey"; "Text"; $key1 ; "UTF-8"; "AES-128-CFB"; "text"; "Hello") \]   
Set Variable \[ $key3 ; Value: MBS ( "[RSA.DecryptPrivateKey](RSADecryptPrivateKey.md)"; "Text"; $key1 ; "UTF-8"; "text"; "Hello") \]  
### See also

- [Encryption.Cipher](EncryptionCipher.md)
- [RSA.DecryptPrivateKey](RSADecryptPrivateKey.md)
- [RSA.GeneratePrivateKey](RSAGeneratePrivateKey.md)

### Release notes

- **Version 7.5**
    - Added [RSA.DecryptPrivateKey](http://www.mbsplugins.eu/RSADecryptPrivateKey.shtml) and [RSA.EncryptPrivateKey](http://www.mbsplugins.eu/RSAEncryptPrivateKey.shtml) functions.

### Blog Entries

- [MBS FileMaker Plugin, version 7.5pr2](https://www.mbsplugins.de/archive/2017-10-16/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 15th October 2017 , last changed 16th October 2017

  
[RSA.DecryptPrivateKey](RSADecryptPrivateKey.md) - [RSA.GeneratePrivateKey](RSAGeneratePrivateKey.md)

[HTML Version](RSAEncryptPrivateKey.shtml)