
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 {
	public static final String ALGORITHM = "RSA";
	public static final String PUBLIC_KEY_FILENAME = "public";
	public static final String PRIVATE_KEY_FILENAME = "private";
	private static final String DIGITS = "0123456789abcdef";
	
    public static void main(String[] args) {
		Security.addProvider(new BouncyCastleProvider());
		Provider bc = Security.getProvider("BC");
		
		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();

		try {
			FileOutputStream privateKeyOutput = new FileOutputStream(PRIVATE_KEY_FILENAME);
			FileOutputStream publicKeyOutput = new FileOutputStream(PUBLIC_KEY_FILENAME);
			X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKey.getEncoded());
			PKCS8EncodedKeySpec privateKeySpec = new PKCS8EncodedKeySpec(privateKey.getEncoded());
			publicKeyOutput.write(publicKeySpec.getEncoded());
			privateKeyOutput.write(privateKeySpec.getEncoded());
			privateKeyOutput.close();
			publicKeyOutput.close();
		} 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();
    }
}

@@ -644,66 +644,8 @@
 e%22;%0A
-%09private static final String DIGITS = %220123456789abcdef%22;%0A
 %09%0A  
@@ -1793,468 +1793,11 @@
 %7D%0A%09%09
-%0A%09
 %09%0A%09%7D%0A
-    %0A%09public static String toHex(byte%5B%5D data) %7B%0A%09%09return toHex(data, data.length);%0A%09%7D%0A%09%0A%09public static String toHex(byte%5B%5D data, int length)%0A    %7B%0A        StringBuffer%09buf = new StringBuffer();%0A        %0A        for (int i = 0; i != length; i++)%0A        %7B%0A            int%09v = data%5Bi%5D & 0xff;%0A            %0A            buf.append(DIGITS.charAt(v %3E%3E 4));%0A            buf.append(DIGITS.charAt(v & 0xf));%0A        %7D%0A        %0A        return buf.toString();%0A    %7D%0A
 %7D%0A

Update Gen Remove static methods that are no longer used.