Back to forum list… Back to How Do I?...

Encrypt File using PGP/GPG (5 replies)

RogerD
4 years ago
RogerD 4 years ago

As a step in an integration I am trying to encrypt a file using the command

gpg -r [email protected] --encrypt C:\Iman\OutputData\Sage_Inv_20200011.csv

this command works perfect in a command window but in the integration I get this error

The file is not created, there are no other messages. I have also tried executing the step under my user ID to the same result.

Support
4 years ago
Support 4 years ago

Roger, you would do this in a Script Task.

Below is a sample script (yes it's long)....

'This function runs a PGP Extraction process. 
'Encrypts all the GPG files for upload to Concur

Const FILE_PATH = "C:\IMan\OutputData"
Const GPG_EXE_PATH = """C:\Program Files (x86)\GnuPG\bin\gpg.exe"""
Const ENCRYPT_BATCH_FILE = "exec.bat"
Const TXT_EXT = "txt"

Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

sDirectory = FILE_PATH
sExtractDirectory = fso.BuildPath(FILE_PATH, EXTRACT_DIRECTORY)
sEncryptBatchFile = fso.BuildPath(sDirectory, ENCRYPT_BATCH_FILE)

Set GetAllFiles = CreateObject("Scripting.Dictionary")

' start the search
Set objFolder = fso.GetFolder(sDirectory)
Set objFiles = objFolder.Files
For Each objFile In objFiles
    If fso.GetExtensionName(objFile) = TXT_EXT Then
        GetAllFiles.Add objFile, objFile
    End If
Next

For Each Item In GetAllFiles.Keys
    If Item <> "" Then
        sFile = Item
        If fso.FileExists(sFile) Then
            Set tso = fso.CreateTextFile(sEncryptBatchFile, True, False)
            tso.WriteLine "echo off"
            sBatchCmd = GPG_EXE_PATH & " --encrypt -r [email protected] """ & sFile & """"
            tso.WriteLine sBatchCmd
            tso.WriteLine "echo on"
            tso.Close

            objShell.Run """" & sEncryptBatchFile & """", 1, True

        End If
    End If
Next

If fso.FileExists(sEncryptBatchFile) Then
    fso.DeleteFile sEncryptBatchFile, True
End If

Set tso = Nothing
Set fso = Nothing
Set colFiles = Nothing

0

Support
4 years ago
Support 4 years ago

The script is a bit tricky....we dynamically generate a batch file which is then executed.

RogerD
4 years ago
RogerD 4 years ago

Thanks for this, I never would have thought of this approach, but its still not working for me. If I load the job, and execute the step containing the script nothing happens. No errors, and no encrypted files, even though they are files in the directory that should be processed. If I run the step a second time I get the error "An object with the given name has already been added" and still no encrypted files. 

I altered the script so it would not delete the exec.bat file and then exited Iman and came back in so I had a new session. The first time I run the step the exce.bat file gets created, the contents are correct, but I dont think it is executing it, there are no encrypted files. At that point if I open a command window and manually execute the .bat file the files are processed correctly. (If I run the step a second time, I get the same error as above and no exec.bat file is created)

To summarize, the first time the script is used it is creating the .bat file but failing to run it, there are no encrypted files, there are no errors. The second time the script is fired (in the same Iman session) the error message is displayed, no bat file is created, and there are no encrypted files. Overall I am getting the same results that I had with my original script. 

I have attached my integration with the script

 

 

 

RogerD
4 years ago
RogerD 4 years ago

File attached....

Support
4 years ago
Support 4 years ago

FYI You need to run IMan under a specific Windows user due to the nature of the script.

The Permissions function provides the user with the rights to launch shell processes.

Contact

Realisable Software Ltd provides code-free, cost-effective applications integration solutions for SMEs. Our core IMan product is designed to integrate almost any application with a number of Sage solutions and online payment processors.

Looking to purchase IMan, please see our resellers here.

Realisable Software
Ph: +44 (0) 208 123 1017

Copyright © Realisable. All rights reserved.
Realisable is a registered trademark

Close

Request Demo

Realisable Software Ltd provides code-free, cost-effective applications integration solutions for SMEs. Our core IMan product is designed to integrate almost any application with a number of Sage solutions and online payment processors.

Looking to purchase IMan, please see our resellers here.

Realisable Software
Ph: +44 (0) 208 123 1017

Copyright © Realisable. All rights reserved.
Realisable is a registered trademark

Close

Access Downloads

Realisable Software Ltd provides code-free, cost-effective applications integration solutions for SMEs. Our core IMan product is designed to integrate almost any application with a number of Sage solutions and online payment processors.

Looking to purchase IMan, please see our resellers here.

Realisable Software
Ph: +44 (0) 208 123 1017

Copyright © Realisable. All rights reserved.
Realisable is a registered trademark

Close