
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;

public class Gen {
	private static final String DIGITS = "0123456789abcdef";
	
    public static void main(String[] args) {
		Security.addProvider(new BouncyCastleProvider());
		Provider bc = Security.getProvider("BC");
		
		String algorithm = "RSA";
		int keysize = 1024;
		KeyPairGenerator kg = null;
		try {
			kg = KeyPairGenerator.getInstance(algorithm, bc);
			kg.initialize(keysize);
		} catch (NoSuchAlgorithmException e) {
			System.out.println("Can't find algorithm " + algorithm);
			System.exit(-1);
		}
		
		KeyPair keyPair = kg.generateKeyPair();
		PrivateKey privateKey = keyPair.getPrivate();
		PublicKey publicKey = keyPair.getPublic();

		String privateKeyFileName = "private";
		String publicKeyFileName = "public";
		try {
			FileOutputStream privateKeyOutput = new FileOutputStream(privateKeyFileName);
			FileOutputStream publicKeyOutput = new FileOutputStream(publicKeyFileName);
			X509EncodedKeySpec X509 = new X509EncodedKeySpec(publicKey.getEncoded());
			privateKeyOutput.write(X509.getEncoded());
			PKCS8EncodedKeySpec PKCS8 = new PKCS8EncodedKeySpec(privateKey.getEncoded());
			publicKeyOutput.write(PKCS8.getEncoded());
		} catch (IOException e) {
			System.out.println("Can't write key to disk");
		}
		
		
	}
    
	public static String toHex(byte[] data) {
		return toHex(data, data.length);
	}
	
	public static String toHex(byte[] data, int length)
    {
        StringBuffer	buf = new StringBuffer();
        
        for (int i = 0; i != length; i++)
        {
            int	v = data[i] & 0xff;
            
            buf.append(DIGITS.charAt(v >> 4));
            buf.append(DIGITS.charAt(v & 0xf));
        }
        
        return buf.toString();
    }
}

@@ -387,24 +387,25 @@
 dedKeySpec;%0A
+%0A
 import org.b
@@ -471,16 +471,185 @@
 s Gen %7B%0A
+%09public static final String ALGORITHM = %22RSA%22;%0A%09public static final String PUBLIC_KEY_FILENAME = %22public%22;%0A%09public static final String PRIVATE_KEY_FILENAME = %22private%22;%0A
 %09private
@@ -848,36 +848,8 @@
 %0A%09%09%0A
-%09%09String algorithm = %22RSA%22;%0A
 %09%09in
@@ -941,25 +941,25 @@
 nstance(
-algorithm
+ALGORITHM
 , bc);%0A%09
@@ -1073,25 +1073,25 @@
 thm %22 + 
-algorithm
+ALGORITHM
 );%0A%09%09%09Sy
@@ -1252,88 +1252,8 @@
 );%0A%0A
-%09%09String privateKeyFileName = %22private%22;%0A%09%09String publicKeyFileName = %22public%22;%0A
 %09%09tr
@@ -1320,26 +1320,28 @@
 eam(
-privateKeyFileName
+PRIVATE_KEY_FILENAME
 );%0A%09
@@ -1402,25 +1402,27 @@
 eam(
-publicKeyFileName
+PUBLIC_KEY_FILENAME
 );%0A%09

Update Gen Extract filename of public key and private key and the algorithm as public constants.