--- title: "Encrypt File" slug: "encrypt-file" tags: ["PGP module", "Encryption", "public key"] updated: 2023-09-06T20:39:04Z published: 2023-09-06T20:39:04Z canonical: "documentation.decisions.com/encrypt-file" --- > ## Documentation Index > Fetch the complete documentation index at: https://documentation.decisions.com/llms.txt > Use this file to discover all available pages before exploring further. # Encrypt File | ## Step Details | | --- | | **Introduced in Version** | 4.0.0 | | **Last Modified in Version** | 8.5.0 | | **Location** | PGP Steps | The **Encrypt File** step allows a user to use the PGP module to encrypt a file. ### Prerequisites This step requires the [PGP module](https://documentation.decisions.com/docs/pgp-module-overview) to be [installed](https://documentation.decisions.com/docs/installing-modules-decisions) before it will be available in the toolbox. --- ## Properties #### Inputs | Property | Description | Data Type | | --- | --- | --- | | Binary | Defines whether the output file is encrypted as bytes or raw text/ascii | Boolean | | Data | The desired file to encrypt | List of Byte | | Internal File Name | Specifies the filename and file type extension of the file when decrypting the file (i.e., text.pdf). It is best practice to have this match what is entered in the Data field. | String | | Output File Name | Specifies the file name and file type extension of the encrypted file (i.e., newFile.pdf) | String | | Public Key | Generated PGP public key file used to encrypt file | List of Byte | #### Outputs | Property | Description | Data Type | | --- | --- | --- | | Output | Outputs the encrypted file as the specified output file name | String | --- ## Example Inputs and Outputs | Binary | Data | Internal File Name | Output File Name | Public Key | Output | | --- | --- | --- | --- | --- | --- | | False | Content | image.png | encryptedImageFile.png | pub.asc | id:"f196435c-2f2d-4667-98b6-a5d36a3f88a8",FileName:"encryptedImageFile.png",Length:70451 ,Filetype:".png" | | True | Null | example.txt | encryptex.txt | pub.asc | EXCEPTION MESSAGE | | Empty | Content | new.txt | encr.txt | pub.asc | EXCEPTION MESSAGE | | False | Content | Null | file.docx | pub.asc | id:"dbb01f7c-2ebe-4ea7-bf56-2467ce731c67",FileName:"file.docx",Length:3687,Filetype:".docx" | | True | Content | example.pdf | Null | pub.asc | EXCEPTION MESSAGE | | False | Content | read.pdf | file.pdf | Null | EXCEPTION MESSAGE | #### ![](https://cdn.document360.io/6ef8bcc1-6489-4486-9ad1-83acff7e5df0/Images/Documentation/image-1675284049182.png) --- ## Common Errors ### Buffer can't be null If the Data field or the Public Key fields are null or empty, the step will cause an error. To correct this, ensure that a File is uploaded and that the appropriate Public Key file is uploaded to the fields. #### Exception Message: ```csharp Exception Stack Trace: DecisionsFramework.Design.Flow.ErrorRunningFlowStep: Error running step Encrypt File 1[EncryptFile] in flow [Flow 2]: Exception invoking method EncryptFile on class PGPSteps ---> DecisionsFramework.LoggedException: Exception invoking method EncryptFile on class PGPSteps ---> System.ArgumentNullException: Buffer cannot be null. (Parameter 'buffer' at System.IO.MemoryStream..ctor(Byte[] buffer at Decsisions.PGP.Steps.PGPSteps.EncryptFile(Byte[] publicKey, Byte[] data, Boolean binary, String outputFileName, String internalFileName) --- End of inner exception stack trace --- at DecisionsFramework.Design.Flow.StepImplementations.InvokeMethodStep.Run(StepStartData data at DecisionsFramework.Design.Flow.FlowStep.RunStepInternal(String flowTrackingID, String stepTrackingID, KeyValuePairDataStructure[] stepRunDataValues, AbstractFlowTrackingData trackingData at DecisionsFramework.Design.Flow.FlowStep.Start(String flowTrackingID, String stepTrackingID, FlowStateData data, AbstractFlowTrackingData trackingData, RunningStepData currentStepData) --- End of inner exception stack trace --- ``` --- ### Parameter 'binary' of 'EncryptFile' can not be null If the Binary field is empty or null, the step will cause an error. To correct this, set the input mapping of the Binary field to Constant. #### Exception Message: ```csharp Exception Stack Trace: DecisionsFramework.BusinessRuleException: [BusinessRule] Parameter 'binary' of 'EncryptFile' can not be null at DecisionsFramework.Design.Flow.CoreSteps.InvokeMethodUtility.ThrowErrorIfNullIsNotAllowed(MethodInfo methodInfo, Object[] parameterValues, String errorMessage at DecisionsFramework.Design.Flow.StepImplementations.InvokeMethodStep.Run(StepStartData data at DecisionsFramework.Design.Flow.FlowStep.RunStepInternal(String flowTrackingID, String stepTrackingID, KeyValuePairDataStructure[] stepRunDataValues, AbstractFlowTrackingData trackingData at DecisionsFramework.Design.Flow.FlowStep.Start(String flowTrackingID, String stepTrackingID, FlowStateData data, AbstractFlowTrackingData trackingData, RunningStepData currentStepData) ``` --- ### Object reference not set to an instance of an object. If the Output File Name field is empty or null, the step will cause an error. To correct this, ensure that the value is correctly entered or mapped and includes the file extension (ie. .txt, .pdf, etc.). #### Exception Message: ```csharp Exception Stack Trace: DecisionsFramework.Design.Flow.ErrorRunningFlowStep: Error running step Encrypt File 1[EncryptFile] in flow [Flow 2]: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object. at DecisionsFramework.Data.DataTypes.FileData.ProcessValueAddedToFlowData(String filePath, Boolean isFilePathFromSearch at DecisionsFramework.Data.DataTypes.FileData.ValueAdded( at DecisionsFramework.Design.Flow.Mapping.KeyValueDictionary.Add(KeyValuePairDataStructure item at DecisionsFramework.Design.Flow.StepImplementations.InvokeMethodStep.Run(StepStartData data at DecisionsFramework.Design.Flow.FlowStep.RunStepInternal(String flowTrackingID, String stepTrackingID, KeyValuePairDataStructure[] stepRunDataValues, AbstractFlowTrackingData trackingData at DecisionsFramework.Design.Flow.FlowStep.Start(String flowTrackingID, String stepTrackingID, FlowStateData data, AbstractFlowTrackingData trackingData, RunningStepData currentStepData) --- End of inner exception stack trace --- ``` --- Related Information Documentation: [PGP Module](https://documentation.decisions.com/docs/pgp-module-overview) Forum Posts: [Email Encrypt / Decrypt With PGP Module](https://support.decisions.com/forum/topic1520-email-encrypt--decrypt-with-pgp-module.aspx) [Error While Encrypting A File Using PGP](https://support.decisions.com/forum/topic1814-error-while-encrypting-a-file-using-pgp.aspx) [PGP Issues With Decrypting Using Private Key](https://support.decisions.com/forum/topic2522-pgp-issues-with-decrypting-using-private-key.aspx) ## Related - [Set PDF Password](/set-password-pdf.md) - [Sign String With SHA256](/sign-string-with-sha256.md) - [Get Bytes From String With Encoding](/get-bytes-from-string-with-encoding.md) - [Get Bytes From Windows 1255 String](/get-bytes-from-windows-1255-string.md)