create test certificate

hello,Would you please tell me, how to create test certificate using java code not from keytool.Thanks in advance
[134 byte] By [raviadhaa] at [2007-10-3 4:13:26]
# 1
Read the API for Certificate, KeyStore, etc. classes.And if this is not enough by itself, then read the Tutorials at Sun for and apply a couple of other methds from the API and a little ingenuity.
masijade.a at 2007-7-14 22:14:30 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 2
Hello Masijade, Thanks for your reply, would you plaease give me proper links for this. i searched the net but i cant find proper link/tutorial.
raviadhaa at 2007-7-14 22:14:30 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 3
I don't believe there is a method to do this in the Java API.Why can't you use keytool?
ejpa at 2007-7-14 22:14:30 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 4

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.

masijade.a at 2007-7-14 22:14:30 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 5

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.

masijade.a at 2007-7-14 22:14:30 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...