# Encrypt Method

Encrypts the input data using the recipient's public key.

## Syntax

publicvoidencrypt();

## Remarks

This method encrypts the input data using the public key specified in RecipientKey.
Alternatively, a certificate may be specified by setting __RecipientCert__

**Input and Output Properties**

The class will determine the source and destination of the input and output based on which properties are set.

The order in which the input properties are checked is as follows:

When a valid source is found the search stops. The order in which the output properties are checked is as follows:

__SetOutputStream__- OutputFile
- OutputMessage: The output data is written to this property if no other destination is specified.

When using streams you may need to additionally set CloseInputStreamAfterProcessing or CloseOutputStreamAfterProcessing.

**Key Size and the Maximum Length of Data**

RSA has an upper limit to the amount of data that can be encrypted or decrypted, also known as message length. This can typically be calculated as the size of the key minus the size of the RSA header and padding.

When not using OAEP, the following formula and table can be referenced. (RSA Key Bytes) - (Header Bytes) = Length of data, where Header Bytes is always 11.

RSA Key Length (bits) | Length (bits) | Length (bytes) |

1024 | 936 | 117 |

2048 | 1960 | 245 |

3072 | 2984 | 373 |

4096 | 4008 | 501 |

When using OAEP, the following formula and table can be referenced. (RSA Key Bytes) - (2 * Hash Length Bytes) - 2 = Length of data. The table below assumes SHA-256 for the hash, so Hash Length Bytes is 32.

RSA Key Length (bits) | Length (bits) | Length (bytes) |

1024 | 496 | 62 |

2048 | 1520 | 190 |

3072 | 2544 | 318 |

4096 | 3568 | 446 |