Usage
-d file.encrypted privatekey.asc 12345
-e -ai file.txt publickey.asc 12345
Jars to be included:
bcmail-jdk15on-160.jar
bcpg-jdk15on-160.jar
bcpkix-jdk15on-160.jar
bcprov-ext-jdk15on-160.jar
bcprov-jdk15on-160.jar
bctls-jdk15on-160.jar
JCE Policy
Update JDK/JRE with unlimited JCE policy
Java Main
package com.sheriff
import java.io.File;
import org.bouncycastle.openpgp.examples.KeyBasedFileProcessor;
public class FileProcessor {
public static void main(String[] args) {
try {
// decryption flow
if (args[0].equalsIgnoreCase("-d")){
// if input file is empty, then skip decryption
if(new File(args[1]).length()==0L){
return;
}
//decrypt
KeyBasedFileProcessor.main(args);
// this is to delete the source file after decryption if needed
new File(args[1]).delete();
return;
}
// encryption flow
if (args[0].equalsIgnoreCase("-e")){
//encrypt
KeyBasedFileProcessor.main(args);
return;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}