Current location: Hot Scripts Forums » Programming Languages » Everything Java » creating a digital certificate using java security or bouncy castle

creating a digital certificate using java security or bouncy castle

 
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 10-30-06, 11:53 AM
coolcoder coolcoder is offline
Newbie Coder
 
Join Date: May 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
creating a digital certificate using java security or bouncy castle

creating a digital certificate using java security or bouncy castle..

i am working in java security..
i need to create a digital certificate using java..
there r tools like keytool

but i need to do using programming in java...
1.doubt 1:

is it possible to create a digital certificate using java security packages alone?
with the present api,i am only able to parse the exisiting certificate...
& not able to create a new one...


doubt 2:

i used the bouncy castle api to create the certificate but it deosnt accept teh signature alogirthm i give...

i tried to give rsa,dsa,etc...
all didnt work out..

this is my code:
Code:
package chapter6;

import java.math.BigInteger;
import java.security.*;
import java.security.cert.X509Certificate;
import java.util.Date;

import javax.security.auth.x500.X500Principal;

import org.bouncycastle.x509.X509V1CertificateGenerator;


/**
 * Basic X.509 V1 Certificate creation.
 */
public class X509V1CreateExample
{
    public static X509Certificate generateV1Certificate(KeyPair pair)
        throws InvalidKeyException, NoSuchProviderException, SignatureException
    {
        // generate the certificate
        X509V1CertificateGenerator  certGen = new X509V1CertificateGenerator();

        certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
        certGen.setIssuerDN(new X500Principal("CN=Test Certificate"));
        certGen.setNotBefore(new Date(System.currentTimeMillis() - 50000));
        certGen.setNotAfter(new Date(System.currentTimeMillis() + 50000));
        certGen.setSubjectDN(new X500Principal("CN=Test Certificate"));
        certGen.setPublicKey(pair.getPublic());
       
// i get error here
 certGen.setSignatureAlgorithm("SHA256WithRSAEncryption");

        return certGen.generateX509Certificate(pair.getPrivate(), "BC");
    }
    
    public static void main(
        String[]    args)
        throws Exception
    {
        // create the keys
        KeyPair          pair = Utils.generateRSAKeyPair();
        
        // generate the certificate
        X509Certificate cert = generateV1Certificate(pair);

        // show some basic validation
        cert.checkValidity(new Date());

        cert.verify(cert.getPublicKey());
        
        System.out.println("valid certificate generated");
    }
}

pls helpppppppppp meeeeeeeeee//

Last edited by Nico; 10-30-06 at 12:10 PM. Reason: Please use [code] wrappers when posting code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 09:54 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.