GnuPG Java Wrapper API

Flattr this!

Yaniv Yemini wrote a small GnuPG Java Wrapper API.
Just had a small look over it.
So to get it your version from here
Here is just a small demo:

import javax.swing.JOptionPane;
public class Loader {
    public static void main (String args[]){
        GnuPG pgp = new GnuPG ();
        String toolChain[] = {"sign", "clearsign", "signAndEncrypt", "encrypt", "decrypt"};
        String message = JOptionPane.showInputDialog(null, 
                                "Message you want to encrypt?", 
                                "Enter your message", 
        String keyID = "0x56B69D6B";
        System.out.println("using message: "+message);
        System.out.println("using key ID: "+keyID);
        for(String tool : toolChain){
            System.out.println("running: "+tool);
                String passPhrase = enterPassPhrase(tool);
                pgp.sign (message, passPhrase);
                String passPhrase = enterPassPhrase(tool);
                pgp.clearSign (message, passPhrase);
                String passPhrase = enterPassPhrase(tool);
                pgp.signAndEncrypt (message, keyID, passPhrase);
                pgp.encrypt (message, keyID);
                String passPhrase = enterPassPhrase(tool);
                pgp.decrypt (message, passPhrase);
            System.out.println("result: " + pgp.getGpg_result() + "nn");
            System.out.println("error: " + pgp.getGpg_err() + "nn");
            System.out.println("exit: " + pgp.getGpg_exitCode() + "nn");
    public static String enterPassPhrase(String usage){
        return JOptionPane.showInputDialog(null, 
                                "Please enter the Passphrase of your private Key for "+usage, 

Unforntunetally there is a Problem with decrypting a message. It is possible to decrypt the String with the gpg CI Version, but within Java it does not work. So maybe the error is on my site :-).

Leave a Reply

%d bloggers like this: