# ElGamal Class

Encrypt and decrypt data with the ElGamal asymmetric key encryption algorithm for public-key cryptography.

## Syntax

```text
ipworksencrypt.ElGamal
```

## Remarks

The ElGamal class is used to encrypt/decrypt data with the ElGamal asymmetric key encryption algorithm for public-key cryptography.

To begin, you must either specify an existing key or create a new key. Existing public or private keys may be specified by setting [Key](#key-property-elgamal-class). To create a new key pair, call [CreateKey](#createkey-method-elgamal-class).

After specifying a key, specify the data you wish to encrypt or decrypt. Call the [Encrypt](#encrypt-method-elgamal-class) or [Decrypt](#decrypt-method-elgamal-class) method to perform the operation.

**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:

- [SetInputStream](#setinputstream-method-elgamal-class)
- [InputFile](#inputfile-property-elgamal-class)
- [InputMessage](#inputmessage-property-elgamal-class)

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

- SetOutputStream
- [OutputFile](#outputfile-property-elgamal-class)
- [OutputMessage](#outputmessage-property-elgamal-class): The output data is written to this property if no other destination is specified.

When using streams, you may need to additionally set [CloseInputStreamAfterProcessing](#CloseInputStreamAfterProcessing) or [CloseOutputStreamAfterProcessing](#CloseOutputStreamAfterProcessing).

An ElGamal key is made up of a number of individual parameters.

The public key consists of the following parameters:

- [P](#ElGamalKey_f_P)
- [G](#ElGamalKey_f_G)
- [Y](#ElGamalKey_f_Y)

The class also includes the [PublicKey](#ElGamalKey_f_PublicKey) field which holds the PEM formatted public key for ease of use. This is helpful if you are in control of both signature creation and verification process. When sending the public key to a recipient, note that not all implementations will support using the PEM formatted value in [PublicKey](#ElGamalKey_f_PublicKey), in which case the individual parameters must be sent.

The private key consists of the following parameters:

- [P](#ElGamalKey_f_P)
- [G](#ElGamalKey_f_G)
- [Y](#ElGamalKey_f_Y)
- [X](#ElGamalKey_f_X)

 The class also includes the [PrivateKey](#ElGamalKey_f_PrivateKey) field which holds the PEM formatted private key for ease of use. This is helpful for storing the private key more easily.

## Property List

*The following is the full list of the properties of the class with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [InputFile](#inputfile-property-elgamal-class) | The file to process. |
| [InputMessage](#inputmessage-property-elgamal-class) | The message to process. |
| [Key](#key-property-elgamal-class) | The ElGamal key used for decryption. |
| [OutputFile](#outputfile-property-elgamal-class) | The output file when encrypting or decrypting. |
| [OutputMessage](#outputmessage-property-elgamal-class) | The output message after processing. |
| [Overwrite](#overwrite-property-elgamal-class) | Indicates whether or not the class should overwrite files. |
| [RecipientKey](#recipientkey-property-elgamal-class) | The recipient's public key used when encrypting. |
| [UseHex](#usehex-property-elgamal-class) | Whether input or output is hex encoded. |

## Method List

*The following is the full list of the methods of the class with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [Config](#config-method-elgamal-class) | Sets or retrieves a configuration setting. |
| [CreateKey](#createkey-method-elgamal-class) | Creates a new key. |
| [Decrypt](#decrypt-method-elgamal-class) | Decrypts the input data using the specified private key. |
| [Encrypt](#encrypt-method-elgamal-class) | Encrypts the input data using the recipient's public key. |
| [Reset](#reset-method-elgamal-class) | Resets the class. |
| [SetInputStream](#setinputstream-method-elgamal-class) | Sets the stream from which the class will read data to encrypt or decrypt. |

## Event List

*The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [Error](#error-event-elgamal-class) | Fired when information is available about errors during data delivery. |

## Config Settings

*The following is a list of config settings for the class with short descriptions. Click on the links for further details.*

|  |  |
| --- | --- |
| [CloseInputStreamAfterProcessing](#CloseInputStreamAfterProcessing) | Determines whether or not the input stream is closed after processing. |
| [CloseOutputStreamAfterProcessing](#CloseOutputStreamAfterProcessing) | Determines whether or not the output stream is closed after processing. |
| [KeySize](#KeySize) | The size, in bits, of the secret key. |
| [BuildInfo](#BuildInfo) | Information about the product's build. |
| [GUIAvailable](#GUIAvailable) | Whether or not a message loop is available for processing events. |
| [LicenseInfo](#LicenseInfo) | Information about the current license. |
| [MaskSensitiveData](#MaskSensitiveData) | Whether sensitive data is masked in log messages. |
| [UseDaemonThreads](#UseDaemonThreads) | Whether threads created by the class are daemon threads. |
| [UseFIPSCompliantAPI](#UseFIPSCompliantAPI) | Tells the class whether or not to use FIPS certified APIs. |
| [UseInternalSecurityAPI](#UseInternalSecurityAPI) | Whether or not to use the system security libraries or an internal implementation. |
| [UseVirtualThreads](#UseVirtualThreads) | Whether threads created by the class use virtual threads instead of platform threads. |

# InputFile Property ([ElGamal](#elgamal-class) Class)

The file to process.

## Syntax

```text
public String getInputFile();
public void setInputFile(String inputFile);
```

## Default Value

""

## Remarks

This property specifies the file to be processed. Set this property to the full or relative path to the file which will be processed.

**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:

- [SetInputStream](#setinputstream-method-elgamal-class)
- InputFile
- [InputMessage](#inputmessage-property-elgamal-class)

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

- SetOutputStream
- [OutputFile](#outputfile-property-elgamal-class)
- [OutputMessage](#outputmessage-property-elgamal-class): The output data is written to this property if no other destination is specified.

When using streams, you may need to additionally set [CloseInputStreamAfterProcessing](#CloseInputStreamAfterProcessing) or [CloseOutputStreamAfterProcessing](#CloseOutputStreamAfterProcessing).

# InputMessage Property ([ElGamal](#elgamal-class) Class)

The message to process.

## Syntax

```text
public byte[] getInputMessage();
public void setInputMessage(byte[] inputMessage);
```

## Default Value

""

## Remarks

This property specifies the message to be processed.

**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:

- [SetInputStream](#setinputstream-method-elgamal-class)
- [InputFile](#inputfile-property-elgamal-class)
- InputMessage

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

- SetOutputStream
- [OutputFile](#outputfile-property-elgamal-class)
- [OutputMessage](#outputmessage-property-elgamal-class): The output data is written to this property if no other destination is specified.

When using streams, you may need to additionally set [CloseInputStreamAfterProcessing](#CloseInputStreamAfterProcessing) or [CloseOutputStreamAfterProcessing](#CloseOutputStreamAfterProcessing).

# Key Property ([ElGamal](#elgamal-class) Class)

The ElGamal key used for decryption.

## Syntax

```text
public ElGamalKey getKey();
public void setKey(ElGamalKey key);
```

## Remarks

This property specifies the ElGamal key used to decrypt data. This property must be set before calling [Decrypt](#decrypt-method-elgamal-class).

An ElGamal key is made up of a number of individual parameters.

The public key consists of the following parameters:

- [P](#ElGamalKey_f_P)
- [G](#ElGamalKey_f_G)
- [Y](#ElGamalKey_f_Y)

The class also includes the [PublicKey](#ElGamalKey_f_PublicKey) field which holds the PEM formatted public key for ease of use. This is helpful if you are in control of both signature creation and verification process. When sending the public key to a recipient, note that not all implementations will support using the PEM formatted value in [PublicKey](#ElGamalKey_f_PublicKey), in which case the individual parameters must be sent.

The private key consists of the following parameters:

- [P](#ElGamalKey_f_P)
- [G](#ElGamalKey_f_G)
- [Y](#ElGamalKey_f_Y)
- [X](#ElGamalKey_f_X)

 The class also includes the [PrivateKey](#ElGamalKey_f_PrivateKey) field which holds the PEM formatted private key for ease of use. This is helpful for storing the private key more easily.

 Please refer to the [ElGamalKey](#elgamalkey-type) type for a complete list of fields.

# OutputFile Property ([ElGamal](#elgamal-class) Class)

The output file when encrypting or decrypting.

## Syntax

```text
public String getOutputFile();
public void setOutputFile(String outputFile);
```

## Default Value

""

## Remarks

This property specifies the file to which the output will be written when [Encrypt](#encrypt-method-elgamal-class) or [Decrypt](#decrypt-method-elgamal-class) is called. This may be set to an absolute or relative path.

This property is only applicable to [Encrypt](#encrypt-method-elgamal-class) and [Decrypt](#decrypt-method-elgamal-class).

**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:

- [SetInputStream](#setinputstream-method-elgamal-class)
- [InputFile](#inputfile-property-elgamal-class)
- [InputMessage](#inputmessage-property-elgamal-class)

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

- SetOutputStream
- OutputFile
- [OutputMessage](#outputmessage-property-elgamal-class): The output data is written to this property if no other destination is specified.

When using streams, you may need to additionally set [CloseInputStreamAfterProcessing](#CloseInputStreamAfterProcessing) or [CloseOutputStreamAfterProcessing](#CloseOutputStreamAfterProcessing).

# OutputMessage Property ([ElGamal](#elgamal-class) Class)

The output message after processing.

## Syntax

```text
public byte[] getOutputMessage();
```

## Default Value

""

## Remarks

This property will be populated with the output from the operation if [OutputFile](#outputfile-property-elgamal-class) and SetOutputStream are not set.

**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:

- [SetInputStream](#setinputstream-method-elgamal-class)
- [InputFile](#inputfile-property-elgamal-class)
- [InputMessage](#inputmessage-property-elgamal-class)

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

- SetOutputStream
- [OutputFile](#outputfile-property-elgamal-class)
- 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](#CloseInputStreamAfterProcessing) or [CloseOutputStreamAfterProcessing](#CloseOutputStreamAfterProcessing).

This property is read-only and not available at design time.

# Overwrite Property ([ElGamal](#elgamal-class) Class)

Indicates whether or not the class should overwrite files.

## Syntax

```text
public boolean isOverwrite();
public void setOverwrite(boolean overwrite);
```

## Default Value

False

## Remarks

This property indicates whether or not the class will overwrite [OutputFile](#outputfile-property-elgamal-class). If Overwrite is False, an error will be thrown whenever [OutputFile](#outputfile-property-elgamal-class) exists before an operation. The default value is False.

# RecipientKey Property ([ElGamal](#elgamal-class) Class)

The recipient's public key used when encrypting.

## Syntax

```text
public ElGamalKey getRecipientKey();
public void setRecipientKey(ElGamalKey recipientKey);
```

## Remarks

This property specifies the recipient's public key. This property must be set before calling [Encrypt](#encrypt-method-elgamal-class).

An ElGamal key is made up of a number of individual parameters.

The public key consists of the following parameters:

- [P](#ElGamalKey_f_P)
- [G](#ElGamalKey_f_G)
- [Y](#ElGamalKey_f_Y)

The class also includes the [PublicKey](#ElGamalKey_f_PublicKey) field which holds the PEM formatted public key for ease of use. This is helpful if you are in control of both signature creation and verification process. When sending the public key to a recipient, note that not all implementations will support using the PEM formatted value in [PublicKey](#ElGamalKey_f_PublicKey), in which case the individual parameters must be sent.

The private key consists of the following parameters:

- [P](#ElGamalKey_f_P)
- [G](#ElGamalKey_f_G)
- [Y](#ElGamalKey_f_Y)
- [X](#ElGamalKey_f_X)

 The class also includes the [PrivateKey](#ElGamalKey_f_PrivateKey) field which holds the PEM formatted private key for ease of use. This is helpful for storing the private key more easily.

 Please refer to the [ElGamalKey](#elgamalkey-type) type for a complete list of fields.

# UseHex Property ([ElGamal](#elgamal-class) Class)

Whether input or output is hex encoded.

## Syntax

```text
public boolean isUseHex();
public void setUseHex(boolean useHex);
```

## Default Value

False

## Remarks

This property specifies whether the encrypted data is hex encoded.

If set to True, when [Encrypt](#encrypt-method-elgamal-class) is called the class will perform the encryption as normal and then hex encode the output. [OutputMessage](#outputmessage-property-elgamal-class) or [OutputFile](#outputfile-property-elgamal-class) will hold hex encoded data.

If set to True, when [Decrypt](#decrypt-method-elgamal-class) is called the class will expect [InputMessage](#inputmessage-property-elgamal-class) or [InputFile](#inputfile-property-elgamal-class) to hold hex encoded data. The class will then hex decode the data and perform decryption as normal.

# Config Method ([ElGamal](#elgamal-class) Class)

Sets or retrieves a configuration setting.

## Syntax

```text
public String config(String configurationString);
```

## Remarks

Config is a generic method available in every class. It is used to set and retrieve [configuration settings](#config-settings-elgamal-class) for the class.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these *internal properties* is provided through the Config method.

To set a configuration setting named *PROPERTY*, you must call *Config("PROPERTY=VALUE")*, where *VALUE* is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a [configuration setting](#config-settings-elgamal-class), you must call *Config("PROPERTY")*. The value will be returned as a string.

# CreateKey Method ([ElGamal](#elgamal-class) Class)

Creates a new key.

## Syntax

```text
public void createKey();
```

## Remarks

This method creates a new public and private key.

When calling CreateKey the [Key](#key-property-elgamal-class) property is populated with a new private and public key.

An ElGamal key is made up of a number of individual parameters.

The public key consists of the following parameters:

- [P](#ElGamalKey_f_P)
- [G](#ElGamalKey_f_G)
- [Y](#ElGamalKey_f_Y)

The class also includes the [PublicKey](#ElGamalKey_f_PublicKey) field which holds the PEM formatted public key for ease of use. This is helpful if you are in control of both signature creation and verification process. When sending the public key to a recipient, note that not all implementations will support using the PEM formatted value in [PublicKey](#ElGamalKey_f_PublicKey), in which case the individual parameters must be sent.

The private key consists of the following parameters:

- [P](#ElGamalKey_f_P)
- [G](#ElGamalKey_f_G)
- [Y](#ElGamalKey_f_Y)
- [X](#ElGamalKey_f_X)

 The class also includes the [PrivateKey](#ElGamalKey_f_PrivateKey) field which holds the PEM formatted private key for ease of use. This is helpful for storing the private key more easily.

# Decrypt Method ([ElGamal](#elgamal-class) Class)

Decrypts the input data using the specified private key.

## Syntax

```text
public void decrypt();
```

## Remarks

This method decrypts the input data using the private key specified in [Key](#key-property-elgamal-class). Alternatively, a certificate may be specified by setting Certificate.

**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:

- [SetInputStream](#setinputstream-method-elgamal-class)
- [InputFile](#inputfile-property-elgamal-class)
- [InputMessage](#inputmessage-property-elgamal-class)

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

- SetOutputStream
- [OutputFile](#outputfile-property-elgamal-class)
- [OutputMessage](#outputmessage-property-elgamal-class): The output data is written to this property if no other destination is specified.

When using streams, you may need to additionally set [CloseInputStreamAfterProcessing](#CloseInputStreamAfterProcessing) or [CloseOutputStreamAfterProcessing](#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 |

# Encrypt Method ([ElGamal](#elgamal-class) Class)

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

## Syntax

```text
public void encrypt();
```

## Remarks

This method encrypts the input data using the public key specified in [RecipientKey](#recipientkey-property-elgamal-class). 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:

- [SetInputStream](#setinputstream-method-elgamal-class)
- [InputFile](#inputfile-property-elgamal-class)
- [InputMessage](#inputmessage-property-elgamal-class)

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

- SetOutputStream
- [OutputFile](#outputfile-property-elgamal-class)
- [OutputMessage](#outputmessage-property-elgamal-class): The output data is written to this property if no other destination is specified.

When using streams, you may need to additionally set [CloseInputStreamAfterProcessing](#CloseInputStreamAfterProcessing) or [CloseOutputStreamAfterProcessing](#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 |

# Reset Method ([ElGamal](#elgamal-class) Class)

Resets the class.

## Syntax

```text
public void reset();
```

## Remarks

When called, the class will reset all of its properties to their default values.

# SetInputStream Method ([ElGamal](#elgamal-class) Class)

Sets the stream from which the class will read data to encrypt or decrypt.

## Syntax

```text
public void setInputStream(java.io.InputStream inputStream);
```

## Remarks

This method sets the stream from which the class will read data to encrypt or decrypt.

**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:

- SetInputStream
- [InputFile](#inputfile-property-elgamal-class)
- [InputMessage](#inputmessage-property-elgamal-class)

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

- SetOutputStream
- [OutputFile](#outputfile-property-elgamal-class)
- [OutputMessage](#outputmessage-property-elgamal-class): The output data is written to this property if no other destination is specified.

When using streams, you may need to additionally set [CloseInputStreamAfterProcessing](#CloseInputStreamAfterProcessing) or [CloseOutputStreamAfterProcessing](#CloseOutputStreamAfterProcessing).

# Error Event ([ElGamal](#elgamal-class) Class)

Fired when information is available about errors during data delivery.

## Syntax

```text
public class DefaultElGamalEventListener implements ElGamalEventListener {
  ...
  public void error(ElGamalErrorEvent e) {}
  ...
}

public class ElGamalErrorEvent {
  public int errorCode;
  public String description;
}
```

## Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally the class throws an exception.

The *ErrorCode* parameter contains an error code, and the *Description* parameter contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the [Error Codes](#trappable-errors-elgamal-class) section.

# ElGamalKey Type

Contains the typical parameters for the ElGamal algorithm.

## Remarks

This type is made up of fields that represent the private and public key parameters used by the ElGamal algorithm.

An ElGamal key is made up of a number of individual parameters.

The public key consists of the following parameters:

- [P](#ElGamalKey_f_P)
- [G](#ElGamalKey_f_G)
- [Y](#ElGamalKey_f_Y)

The class also includes the [PublicKey](#ElGamalKey_f_PublicKey) field which holds the PEM formatted public key for ease of use. This is helpful if you are in control of both signature creation and verification process. When sending the public key to a recipient, note that not all implementations will support using the PEM formatted value in [PublicKey](#ElGamalKey_f_PublicKey), in which case the individual parameters must be sent.

The private key consists of the following parameters:

- [P](#ElGamalKey_f_P)
- [G](#ElGamalKey_f_G)
- [Y](#ElGamalKey_f_Y)
- [X](#ElGamalKey_f_X)

 The class also includes the [PrivateKey](#ElGamalKey_f_PrivateKey) field which holds the PEM formatted private key for ease of use. This is helpful for storing the private key more easily.

The following fields are available:

- [G](#ElGamalKey_f_G)

- [P](#ElGamalKey_f_P)

- [PrivateKey](#ElGamalKey_f_PrivateKey)

- [PublicKey](#ElGamalKey_f_PublicKey)

- [X](#ElGamalKey_f_X)

- [Y](#ElGamalKey_f_Y)

## Fields

 **G** *String*
*Default Value: ""*

Represents the G parameter for the ElGamal algorithm.

 **GB** *byte[]*
*Default Value: ""*

Represents the G parameter for the ElGamal algorithm.

 **P** *String*
*Default Value: ""*

Represents the P parameter for the ElGamal algorithm.

 **PB** *byte[]*
*Default Value: ""*

Represents the P parameter for the ElGamal algorithm.

 **PrivateKey** *String*
*Default Value: ""*

This field is a PEM formatted private key. The purpose of this field is to allow easier management of the private key parameters by using only a single value.

 **PublicKey** *String*
*Default Value: ""*

This field is a PEM formatted public key. The purpose of this field is to allow easier management of the public key parameters by using only a single value.

 **X** *String*
*Default Value: ""*

Represents the X parameter for the ElGamal algorithm.

 **XB** *byte[]*
*Default Value: ""*

Represents the X parameter for the ElGamal algorithm.

 **Y** *String*
*Default Value: ""*

Represents the Y parameter for the ElGamal algorithm.

 **YB** *byte[]*
*Default Value: ""*

Represents the Y parameter for the ElGamal algorithm.

## Constructors

```text
public ElGamalKey();
```

 The default constructor creates a new ElGamalKey instance but does not assign a public or private key.

```text
public ElGamalKey(byte[] P, byte[] G, byte[] Y);
```

 The public key constructor assigns an existing public key.

```text
public ElGamalKey(byte[] P, byte[] G, byte[] Y, byte[] X);
```

 The private key constructor assigns an existing private key.

# Config Settings ([ElGamal](#elgamal-class) Class)

 The class accepts one or more of the following *configuration settings*. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the class, access to these *internal properties* is provided through the [Config](#config-method-elgamal-class) method.

### ElGamal Config Settings

**CloseInputStreamAfterProcessing**: Determines whether or not the input stream is closed after processing.Determines whether or not the input stream set by [SetInputStream](#setinputstream-method-elgamal-class) is closed after processing is complete. The default value is True.

**CloseOutputStreamAfterProcessing**: Determines whether or not the output stream is closed after processing.Determines whether or not the output stream set by SetOutputStream is closed after processing is complete. The default value is True.

**KeySize**: The size, in bits, of the secret key.This specifies the size, in bits, of the secret key. The minimum key size for ElGamal is 512. The maximum key size is 4096. Note that large values such as 4096 will impact performance. The default value is 1024.

### Base Config Settings

**BuildInfo**: Information about the product's build.When queried, this setting will return a string containing information about the product's build.

**GUIAvailable**: Whether or not a message loop is available for processing events.In a GUI-based application, long-running blocking operations may cause the application to stop responding to input until the operation returns. The class will attempt to discover whether or not the application has a message loop and, if one is discovered, it will process events in that message loop during any such blocking operation.

In some non-GUI applications, an invalid message loop may be discovered that will result in errant behavior. In these cases, setting [GUIAvailable](#GUIAvailable) to *false* will ensure that the class does not attempt to process external events.

**LicenseInfo**: Information about the current license.When queried, this setting will return a string containing information about the license this instance of a class is using. It will return the following information:

- Product: The product the license is for.
- Product Key: The key the license was generated from.
- License Source: Where the license was found (e.g., RuntimeLicense, License File).
- License Type: The type of license installed (e.g., Royalty Free, Single Server).
- Last Valid Build: The last valid build number for which the license will work.

**MaskSensitiveData**: Whether sensitive data is masked in log messages.In certain circumstances it may be beneficial to mask sensitive data, like passwords, in log messages. Set this to *true* to mask sensitive data. The default is *true*.

**UseDaemonThreads**: Whether threads created by the class are daemon threads.If set to True (default), when the class creates a thread, the thread's Daemon property will be explicitly set to True. When set to False, the class will not set the Daemon property on the created thread. The default value is True.

**UseFIPSCompliantAPI**: Tells the class whether or not to use FIPS certified APIs.When set to *true*, the class will utilize the underlying operating system's certified APIs. Java editions, regardless of OS, utilize Bouncy Castle Federal Information Processing Standards (FIPS), while all other Windows editions make use of Microsoft security libraries.

The Java edition requires installation of the FIPS-certified Bouncy Castle library regardless of the target operating system. This can be downloaded from [https://www.bouncycastle.org/fips-java/](https://www.bouncycastle.org/fips-java/). Only the "Provider" library is needed. The jar file should then be installed in a JRE search path.

The following classes must be imported in the application in which the component will be used:

```text
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
```

The Bouncy Castle provider must be added as a valid provider and must also be configured to operate in FIPS mode:

```text
System.setProperty("org.bouncycastle.fips.approved_only","true");
Security.addProvider(new BouncyCastleFipsProvider());
```

When [UseFIPSCompliantAPI](#UseFIPSCompliantAPI) is *true*, Secure Sockets Layer (SSL)-enabled classes can optionally be configured to use the Transport Layer Security (TLS) Bouncy Castle library. When SSLProvider is set to *sslpAutomatic* (default) or *sslpInternal*, an internal TLS implementation is used, but all cryptographic operations are offloaded to the Bouncy Castle FIPS provider to achieve FIPS-compliant operation. If SSLProvider is set to *sslpPlatform*, the Bouncy Castle JSSE will be used in place of the internal TLS implementation.

To enable the use of the Bouncy Castle JSSE take the following steps in addition to the steps above. Both the Bouncy Castle FIPS provider and the Bouncy Castle JSSE must be configured to use the Bouncy Castle TLS library in FIPS mode. Obtain the Bouncy Castle TLS library from [https://www.bouncycastle.org/fips-java/](https://www.bouncycastle.org/fips-java/). The jar file should then be installed in a JRE search path.

The following classes must be imported in the application in which the component will be used:

```text
import java.security.Security;
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;

//required to use BCJSSE when SSLProvider is set to sslpPlatform
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
```

The Bouncy Castle provider must be added as a valid provider and also must be configured to operate in FIPS mode:

```text
System.setProperty("org.bouncycastle.fips.approved_only","true");
Security.addProvider(new BouncyCastleFipsProvider());

//required to use BCJSSE when SSLProvider is set to sslpPlatform
Security.addProvider(new BouncyCastleJsseProvider("fips:BCFIPS"));

//optional - configure logging level of BCJSSE
Logger.getLogger("org.bouncycastle.jsse").setLevel(java.util.logging.Level.OFF);

//configure the class to use BCJSSE
component.setSSLProvider(1); //platform
component.config("UseFIPSCompliantAPI=true");
```

 NOTE: TLS 1.3 support requires the Bouncy Castle TLS library version 1.0.14 or later.

FIPS mode can be enabled by setting the *UseFIPSCompliantAPI* configuration setting to *true*. This is a static setting that applies to all instances of all classes of the toolkit within the process. It is recommended to enable or disable this setting once before the component has been used to establish a connection. Enabling FIPS while an instance of the component is active and connected may result in unexpected behavior.

For more details, please see the [FIPS 140-2 Compliance](https://www.nsoftware.com/kb/articles/fips.rst) article.

NOTE: Enabling FIPS compliance requires a special license; please contact [sales@nsoftware.com](mailto:sales@nsoftware.com) for details.

**UseInternalSecurityAPI**: Whether or not to use the system security libraries or an internal implementation. When set to *false*, the class will use the system security libraries by default to perform cryptographic functions where applicable.

Setting this configuration setting to *true* tells the class to use the internal implementation instead of using the system security libraries.

 This setting is set to *false* by default on all platforms.

**UseVirtualThreads**: Whether threads created by the class use virtual threads instead of platform threads.If set to *true*, when the class creates a thread, it will be created as a virtual thread instead of a platform thread. Virtual threads are lightweight threads managed by the JVM that are multiplexed onto a small pool of carrier threads, significantly reducing memory usage and platform thread count under high-concurrency workloads. Requires Java 24 or later. The default value is *false*.

# Trappable Errors ([ElGamal](#elgamal-class) Class)

### ElGamal Errors

|  |  |
| --- | --- |
| 102 | No Key specified. |
| 104 | Cannot read or write file. |
| 105 | key parameters incorrect. |
| 111 | OutputFile already exists and Overwrite is False. |
| 112 | Invalid length of input message. |
| 304 | Cannot write file. |
| 305 | Cannot read file. |
| 306 | Cannot create file. |
