package org.nanopub.extra.security;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;

import sun.misc.BASE64Encoder;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;

public class MakeKeys {

	@com.beust.jcommander.Parameter(names = "-f", description = "Path and file name of key files")
	private String keyFilename = "~/.nanopub/id_rsa";

	public static void main(String[] args) throws IOException {
		MakeKeys obj = new MakeKeys();
		JCommander jc = new JCommander(obj);
		try {
			jc.parse(args);
		} catch (ParameterException ex) {
			jc.usage();
			System.exit(1);
		}
		try {
			obj.run();
		} catch (Exception ex) {
			ex.printStackTrace();
			System.exit(1);
		}
	}

	private MakeKeys() {
	}

	private void run() throws Exception {

		// Preparation:
		keyFilename = keyFilename.replaceFirst("^~", System.getProperty("user.home"));
		File publicKeyFile = new File(keyFilename + ".pub");
		if (publicKeyFile.exists()) {
			throw new RuntimeException("Key file already exists: " + publicKeyFile);
		}
		File privateKeyFile = new File(keyFilename);
		if (privateKeyFile.exists()) {
			throw new RuntimeException("Key file already exists: " + privateKeyFile);
		}
		File parentDir = privateKeyFile.getParentFile();
		if (parentDir != null) parentDir.mkdir();
		publicKeyFile.createNewFile();
		publicKeyFile.setReadable(true, false);
		publicKeyFile.setWritable(false, false);
		publicKeyFile.setWritable(true, true);
		privateKeyFile.createNewFile();
		privateKeyFile.setReadable(false, false);
		privateKeyFile.setReadable(true, true);
		privateKeyFile.setWritable(false, false);
		privateKeyFile.setWritable(true, true);

		// Creating and writing keys
		KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
		keyPairGenerator.initialize(1024);
		KeyPair keyPair = keyPairGenerator.genKeyPair();
		BASE64Encoder encoder = new BASE64Encoder();
		FileOutputStream outPublic = new FileOutputStream(publicKeyFile);
		outPublic.write((encoder.encode(keyPair.getPublic().getEncoded()) + "\n").getBytes());
		outPublic.close();
		FileOutputStream outPrivate = new FileOutputStream(privateKeyFile);
		outPrivate.write((encoder.encode(keyPair.getPrivate().getEncoded()) + "\n").getBytes());
		outPrivate.close();
	}

}

@@ -180,16 +180,51 @@
 nerator;
+%0Aimport java.security.SecureRandom;
 %0A%0Aimport
@@ -504,17 +504,17 @@
 opub/id_
-r
+d
 sa%22;%0A%0A%09p
@@ -1903,11 +1903,87 @@
 ce(%22
-RSA
+DSA%22, %22SUN%22);%0A%09%09SecureRandom random = SecureRandom.getInstance(%22SHA1PRNG%22, %22SUN
 %22);%0A
@@ -2016,16 +2016,24 @@
 ize(1024
+, random
 );%0A%09%09Key

Use DSA for key pair generation