Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

creating X.509 certificate programming without BouncyCastle .

843811Dec 6 2006 — edited Dec 6 2006
I have received the certificate but I could not understand how to
create the file with correct structure like keytool utility created ?

>>
import sun.security.x509.*;
import java.security.*;
import javax.security.cert .*;

public class GenCert
{
public static void main(String[] args)throws Exception
{
CertAndKeyGen cakg = new CertAndKeyGen("RSA", "MD5WithRSA");
cakg.generate(1024);

PublicKey publicKey = cakg.getPublicKey();
System.out.println(publicKey);

PrivateKey privateKey = cakg.getPrivateKey();
System.out.println(privateKey);

X500Name name = new X500Name("One", "Two", "Three", "Four", "Five", "Six");
System.out.println(name);

X509Cert cert = cakg.getSelfCert(name, 2000000);
System.out.println("cert: "+cert);

X509Certificate certificate = X509Certificate.getInstance(cert.getSignedCert());
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 3 2007
Added on Dec 6 2006
10 comments
408 views