使用m子中的多个密钥进行PGP加密

时间:2018-09-25 01:03:33

标签: encryption mule pgp

鉴于PGP支持使用多个公共密钥的加密,如何在mulesoft中实现呢?

在pgp加密程序选项卡的加密配置窗口的“公共密钥环文件名”字段中添加两个密钥会导致错误为this.state.check: true

是否可以从该加密模块中添加多个公钥,否则如何实现? ule子运行时间:3.8.5

非常感谢您的帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

我通过使用Java组件调用终端并从Java运行时运行gpg crypto命令解决了这一问题。我只是先检查OS,以构建命令字符串来运行其各自的终端

boolean isWindows = System.getProperty("os.name")
              .toLowerCase().startsWith("windows");

/*gpg command options may vary as per your requirement. multiple --recipient option here is the way to encrypt with multiple public keys.
Using StringBuilder helps to build this string from input/dynamic values.
*/

String command = "gpg --pgp6 --armor --batch --output encryptedHelloWorld.pgp --trust-model always --recipient "<part of UserID1 (either name or emailId)>" --recipient "<part of UserID2>" --encrypt helloWorld.txt" 

/*in case you need to change directory to where your file is to encrypt it from one command, you could append this
`"cd"+ <your path to file> "&" + command`  ----> for  windows
`"cd"+ <your path to file> ";" + command`  ----> for linux
*/

public int executeCommand(String command) throws IOException, InterruptedException {
    Process pr;
    if (isWindows) {
        String[] cmd = { "cmd.exe", "/c", command };
        pr = Runtime.getRuntime().exec(cmd);
    }
    else {
        String[] cmd = { "/bin/sh", "-c", command };
        pr = Runtime.getRuntime().exec(cmd);
    }           
    int exitStatus = pr.waitFor();  // this gives you value 0 if success or other than 0 which ties to error message
    errorInputStream = pr.getErrorStream(); //streaming error message

    return exitStatus;
}