web stats
PGP Decryption - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 01-02-2018, 11:56 AM
bxd4 bxd4 is offline
What's HL7?
Join Date: Jul 2012
Posts: 5
bxd4 is on a distinguished road
Post PGP Decryption

The client I am working for wants to encrypt and then decrypt the messages received from the vendor. I am going to receive encrypted messages into Mirth, and need to decrypt them in Mirth before processing them. I am going to use the preprocessor script but I am looking to see if anyone had a Javascript script which would save me lots of time. They are using OpenPGP and the key type is RSA (2048). I have the Public and Private Keys and the password but need the PGP decrypt function to get it to work. If anyone has a workable script and could post it to this thread I would appreciate it.
Also I believe I need the correct jar file to place in the custom-lib and if you have the name of that file that would be helpful.
If anyone has any other suggestions that would be great.
Reply With Quote
Old 01-03-2018, 04:15 AM
amble amble is offline
OBX.2 Kenobi
Join Date: Nov 2015
Posts: 95
amble is on a distinguished road

Seems a lot of overhead decrypting on the fly.....what sort of volume are you taking about - that would be my first concern. Can't you secure the endpoint another way, like an SSL tunnel or VPN?

You might find this helpful: http://www.mirthproject.org/communit...42&postcount=4

Last edited by amble; 01-03-2018 at 04:49 AM.
Reply With Quote
Old 01-03-2018, 05:19 AM
bxd4 bxd4 is offline
What's HL7?
Join Date: Jul 2012
Posts: 5
bxd4 is on a distinguished road

It does seem like a lot of overhead however the vendor is only going to send SFTP and the client wants them to encrypt (using PGP) before sending in order to meet HIPPA regs. I am not sure of the volume because this is all new for the client, however it could become significant.

So I really need to decrypt the messages before processing and sending to the database.

If you have a script please forward. I have looked at those posts but have not found anything.

Reply With Quote
Old 01-03-2018, 06:01 AM
kirbykn2's Avatar
kirbykn2 kirbykn2 is offline
Mirth Guru
Join Date: Sep 2014
Location: Michigan
Posts: 615
kirbykn2 is on a distinguished road

I have not decrypted using PGP, but I have encrypted and decrypted using AES in a JS transformer step. The package I used was OpenSSL and I believe it was already installed.

var messageBytes = Packages.org.apache.commons.ssl.OpenSSL.decrypt("a es-128",new java.lang.String("11111111111111111111111111111111 ").getBytes("UTF-8"),new java.lang.String("1234567890123456").getBytes("UTF-8"), new java.lang.String(msg).getBytes("UTF-8"));
channelMap.put('decryptedData', new java.lang.String(messageBytes, "UTF-8"));


Mirth Certified|Epic Bridges Certified|Cloverleaf Level 2 Certified

Appliance Version 3.11.4
Mirth Connect Version 3.8.0
Java Version 1.6.0_45-b06
Java (64 bit) Version 1.6.0_45-b06
Java 7 (64 bit) Version 1.7.0_151-b15
Java 8 (64 bit) Version 1.8.0_181-b13
PostgreSQL Version 9.6.8
Reply With Quote
Old 01-03-2018, 06:57 AM
bxd4 bxd4 is offline
What's HL7?
Join Date: Jul 2012
Posts: 5
bxd4 is on a distinguished road

Thanks for the reply.

How can I check to see if the package is already installed and if it's not installed where can I get it from?
The client is using OpenPGP and I have to stick to that. I have to use their public and private keys and their password.

Reply With Quote
Old 01-11-2018, 03:42 AM
robrud robrud is offline
Mirth Newb
Join Date: Oct 2015
Posts: 12
robrud is on a distinguished road

Hallo. We encrypt messages in Mirth 3.3.2 running on Ubuntu with GnuPG by calling the gpg-commands via JavaScript.

1. save plain-content to a new file on local filesystem 2. encrypt 3. read encrypted local file binary and process in mirth

Here the code for step 2.
var gpgp = java.lang.Runtime.getRuntime().exec('gpg --trust-model always --homedir ' + gpghome + ' --default-key mirth@*.* --batch -r ' + gpgrecipient + ' -o ' + outfilename + ' -e ' + infilename);
var stdoutConsumer = new StreamConsumer(gpgp.getInputStream());
var stderrConsumer = new StreamConsumer(gpgp.getErrorStream());

var gpgp_stdout = stdoutConsumer.getOutput();
var gpgp_stderr = stderrConsumer.getOutput();
The certificates are managed on the Linux-System with the gpg-commands.
gpg --homedir /appdata/mirth/local/gpg/keyring_ealarm/ --import /appdata/mirth/local/gpg/eAlarm.key
Function streamconsumer is from the forum:
/** http://www.mirthcorp.com/community/forums/showthread.php?t=6902&highlight=shell&page=4
function StreamConsumer(is, charset) {
	var output = '';
	var thread = new java.lang.Thread({
		run: function() {
			if (typeof charset !== 'undefined') {
				output = org.apache.commons.io.IOUtils.toString(is, charset);
			} else {
				output = org.apache.commons.io.IOUtils.toString(is);

	this.interrupt = function() {

	this.getOutput = function() {
		return output;

Links: https://www.gnupg.org
Reply With Quote

decryption, pgp, pgp decryption

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -8. The time now is 04:45 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.
Mirth Corporation