-2

I have good examples on how to call the Bouncy Castle algorithm from Java. But I am new to Mirth and JavaScript. Please help me to translate the below java program to JavaScript?

Source: https://forums.mirthproject.io/forum...ncryption-help

public static byte[] encrypt(
    byte[] dataToEncrypt,
    char[] passPhrase,
    int algorithm,
    boolean armor
) throws IOException, PGPException, NoSuchProviderException
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();

    OutputStream out = bOut;
    if (armor)
    {
        out = new ArmoredOutputStream(out);
    }

    PGPEncryptedDataGenerator encGen = new PGPEncryptedDataGenerator(new JcePGPDataEncryptorBuilder(algorithm).setSecureRan dom(new SecureRandom()).setProvider("BC"));
    encGen.addMethod(new JcePBEKeyEncryptionMethodGenerator(passPhrase).set Provider("BC"));

    OutputStream encOut = encGen.open(out, dataToEncrypt.length);

    encOut.write(dataToEncrypt);
    encOut.close();

    if (armor)
    {
        out.close();
    }

    return bOut.toByteArray();
}

byte[] encrypted = encrypt(dataToEncrypt, passArray, PGPEncryptedDataGenerator.CAST5, true);
sgowd
  • 946
  • 3
  • 10
  • 27
  • Have you considered adding your java code as a resource? As described here: [How to create and invoke custom Java code in Mirth Connect](http://www.mirthcorp.com/community/wiki/display/mirth/How+to+create+and+invoke+custom+Java+code+in+Mirth+Connect) – tobifasc Oct 19 '21 at 06:54

1 Answers1

0

The link here points to a Javascript implementation of the said Algorithm. You can implement this within a transformer step of the source connector. Better still, you can compile the above code into a jar file that you can load to Mirth Connect's custom libs folder. A good starting point for working with custom Java codes is this