« SortedProperties | Main | VirtualBox error: fixing VDI already registered »

GnuPG Java Wrapper API

Yaniv Yemini wrote a small GnuPG Java Wrapper API. Just had a small look over it. So to get it your version from here: http://www.macnews.co.il/mageworks/java/gnupg Here is just a small demo:
import javax.swing.JOptionPane;

import org.gpg.java.GnuPG;

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", JOptionPane.QUESTION_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);
		if(tool.equals("sign")){
			String passPhrase = enterPassPhrase(tool);
			pgp.sign (message, passPhrase);				
		}

		if(tool.equals("clearsign")){
			String passPhrase = enterPassPhrase(tool);
			pgp.clearSign (message, passPhrase);				
		}			
		if(tool.equals("signAndEncrypt")){
			String passPhrase = enterPassPhrase(tool);
			pgp.signAndEncrypt (message, keyID, passPhrase);				
		}
		if(tool.equals("encrypt")){
			pgp.encrypt (message, keyID);				
		}	
		if(tool.equals("decrypt")){
			String passPhrase = enterPassPhrase(tool);
			pgp.decrypt (message, passPhrase);				
		}				
		System.out.println("result: " + pgp.getGpg_result() + "\n\n");
		System.out.println("error: " + pgp.getGpg_err() + "\n\n");
		System.out.println("exit: " + pgp.getGpg_exitCode() + "\n\n");
	}
}
    
    public static String enterPassPhrase(String usage){
    	return JOptionPane.showInputDialog(null, "Please enter the Passphrase of your private Key for "+usage, "Passphrase", JOptionPane.QUESTION_MESSAGE);
    }

}
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 :-).
Blogged with the Flock Browser

TrackBack

TrackBack URL for this entry:
http://www.innoq.com/movabletype/mt-tb.cgi/3084

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on March 28, 2009 7:25 PM.

The previous post in this blog was SortedProperties.

The next post in this blog is VirtualBox error: fixing VDI already registered.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.31