RSA.GeneratePrivateKey
----------------------

Creates a new private key.

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

MBS( "RSA.GeneratePrivateKey" { ; Bits; Exp; Algorithm; PasswordType; PasswordData; PasswordEncoding } ) 

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

### Result

Returns key as text or error.

### Description

Creates a new private key.  
Returns the PEM formatted key as text.  
  
As the PEM format contains base64 encoded DER data, you can remove header and footer line and use the result as base64 encoded DER key.  
  
If you specify an algorithm and a key, we encrypt the PEM file. (New in 7.5)  
### Examples

Generate keys:

 Set Variable \[$privateKey ; Value:MBS ( "RSA.GeneratePrivateKey")\]  
Set Variable \[$publickey ; Value:MBS ( "[RSA.GetPublicKey](RSAGetPublicKey.md)"; "text"; $privateKey ; "UTF-8")\]  
Set Field \[Table::PrivateKey ; $privateKey \]  
Set Field \[Table::PublicKey ; $publicKey \]  
Generate key with text password:

 MBS ( "RSA.GeneratePrivateKey"; 4096; 65537; "AES-128-CBC"; "text"; "Hello" )  
### See also

- [Encryption.Cipher](EncryptionCipher.md)
- [RSA.DecryptPrivateKey](RSADecryptPrivateKey.md)
- [RSA.EncryptPrivateKey](RSAEncryptPrivateKey.md)
- [RSA.GetPublicKey](RSAGetPublicKey.md)
- [RSA.PrivateDecrypt](RSAPrivateDecrypt.md)
- [RSA.PrivateEncrypt](RSAPrivateEncrypt.md)
- [RSA.PublicDecrypt](RSAPublicDecrypt.md)
- [RSA.PublicEncrypt](RSAPublicEncrypt.md)

### Release notes

- **Version 10.0**
    - Improved error messages for [RSA.GeneratePrivateKey](https://www.mbsplugins.eu/RSAGeneratePrivateKey.shtml), [RSA.Verify](https://www.mbsplugins.eu/RSAVerify.shtml), [RSA.Sign](https://www.mbsplugins.eu/RSASign.shtml).
- **Version 7.5**
    - Improved [RSA.GeneratePrivateKey](http://www.mbsplugins.eu/RSAGeneratePrivateKey.shtml) to allow you to specify algorithm and encrypt keys.

### Example Databases

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

### Blog Entries

- [MBS FileMaker Plugin, version 10.0pr5](https://www.mbsplugins.de/archive/2020-01-02/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.5pr2](https://www.mbsplugins.de/archive/2017-10-16/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 6.2 for OS X/Windows](https://www.mbsplugins.de/archive/2016-05-24/MBS_FileMaker_Plugin_62_for_OS/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 6.2pr1](https://www.mbsplugins.de/archive/2016-03-19/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

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

  
[RSA.EncryptPrivateKey](RSAEncryptPrivateKey.md) - [RSA.GetPublicKey](RSAGetPublicKey.md)

[HTML Version](RSAGeneratePrivateKey.shtml)