Well, it seems the only way to do it, without already having a certificate to import, is with a class in the sun package (and its associated warnings about support). Here an example:
private static void genKeyNStore( String alias, char[] password,
String outputFilename )
throws Exception
{
KeyStore keyStore = KeyStore.getInstance( "JKS" );
keyStore.load( null, password );
sun.security.x509.CertAndKeyGen keypair = new sun.security.x509.CertAndKeyGen("RSA", "MD5WithRSA" );
sun.security.x509.X500Name x500Name = new sun.security.x509.X500Name(
"IGEL RemoteManager", "IGEL Technology GmbH",
"IGEL Technology GmbH", "DE");
keypair.generate( 1024 );
PrivateKey privKey = keypair.getPrivateKey();
X509Certificate[] chain = new X509Certificate[1];
chain[0] = keypair.getSelfCertificate(x500Name, 7000*24*60*60);
keyStore.setKeyEntry(alias, privKey, password, chain);
OutputStream out = new FileOutputStream( outputFilename );
keyStore.store( out, password );
}
This has come from an earlier thread:
http://forum.java.sun.com/thread.jspa?forumID=9&threadID=535212
There are KeyPairGenerators under java.security, but I have not, as yet, found a method to generate a Certificate from these. So nearly all of the can be performed with the java.security classes, excpet the actual certificate generation. You may wish to more fully investigate this, however.
Also, sorry about the first post. I have, numerous times, created things to take certificates from all over the place in nearly all formats and create keystores out of them. This is not hard and easily figured out using the API and nearly any SSL example displaying keystores. My first knee-jerk reaction was to assume that this was the sort of thing you wanted. But these things assume that a Certificate, at least, is available and you are only playing with key and trust stores. But to actually create a certificate, is, as you can see, not so easily done.
With the official API, I believe, like ejp, that it cannot be done. Using sun package classes it can (I am fairly sure that these are the things that keytool itself uses), but once again, those are not documented and are subject to change without warning.