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

Reply
  #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 TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-01-06, 08:11 PM
King Coder King Coder is offline
Community VIP
 
Join Date: Jan 2006
Posts: 703
Thanks: 0
Thanked 0 Times in 0 Posts
Would the XML Digital Signature API be of interest to you? From what I can tell it may be what you're after.
__________________
my site
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 08-03-09, 04:28 PM
PinwinitO Developer PinwinitO Developer is offline
New Member
 
Join Date: Aug 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Hi... you need add the next line:

Security.addProvider(new BouncyCastleProvider());

before:

// generate the certificate
X509V1CertificateGenerator certGen = new X509V1CertificateGenerator();

good luck...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

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 10:43 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.