Quantcast

Creating a PKCS#10 Certificate Request

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Creating a PKCS#10 Certificate Request

Kasun Sanjeewa Perera
Hi,

I am new to bouncy castle. I wish to know how to create a PKCS#10 Certificate Request using bouncy castle in JAVA. Here is my code. But I don't know the meanings of highlighted methods. Can someone send me a example of Certificate Request Generation.

        AlgorithmIdentifier algo=new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption,new DERNull());

        //RSA key generation
        RSA rsa=new RSA();  // my rsa key generation class
        BigInteger bInt = new BigInteger("17");
        rsa.setKey(bInt, 1024, 100);
        RSAKeyParameters pubkey= rsa.getPublicKey();

        //key structure
        RSAPublicKeyStructure keystruct=new RSAPublicKeyStructure(pubkey.getModulus(), pubkey.getExponent());

        //subject key info
        SubjectPublicKeyInfo pubkeyinfo=new SubjectPublicKeyInfo(algo, keystruct);

        //X509 name
        X509Name name=new X509Name("C=LK,CN=kasun,O=UOC,OU=UCSC");

        //asn set
        DERSet asnset=new DERSet();
        //der bit strings
        DERBitString bitstring=new DERBitString();  // here also what to give as byte array for constructer

        CertificationRequestInfo info=new CertificationRequestInfo(name, pubkeyinfo, asnset);
        CertificationRequest Req=new CertificationRequest(info, algo, bitstring);


Thank you,


--
Kasun Sanjeewa Perera
UCSC
University of Colombo
Sri Lanka.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Creating a PKCS#10 Certificate Request

martijn.list
See
http://www.bouncycastle.org/wiki/display/JA1/X.509+Public+Key+Certificate+and+Certification+Request+Generation

Martijn Brinkers

Kasun Sanjeewa Perera wrote:

> Hi,
>
> I am new to bouncy castle. I wish to know how to create a PKCS#10
> Certificate Request using bouncy castle in JAVA. Here is my code. But I
> don't know the meanings of highlighted methods. Can someone send me a
> example of Certificate Request Generation.
>
>         AlgorithmIdentifier algo=new
> AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption,new DERNull());
>
>         //RSA key generation
>         RSA rsa=new RSA();  // my rsa key generation class
>         BigInteger bInt = new BigInteger("17");
>         rsa.setKey(bInt, 1024, 100);
>         RSAKeyParameters pubkey= rsa.getPublicKey();
>
>         //key structure
>         RSAPublicKeyStructure keystruct=new
> RSAPublicKeyStructure(pubkey.getModulus(), pubkey.getExponent());
>
>         //subject key info
>         SubjectPublicKeyInfo pubkeyinfo=new SubjectPublicKeyInfo(algo,
> keystruct);
>
>         //X509 name
>         X509Name name=new X509Name("C=LK,CN=kasun,O=UOC,OU=UCSC");
>
>         //asn set
>         DERSet asnset=new DERSet();
>         //der bit strings
>         DERBitString bitstring=new DERBitString();  // here also what to
> give as byte array for constructer
>
>         CertificationRequestInfo info=new CertificationRequestInfo(name,
> pubkeyinfo, asnset);
>         CertificationRequest Req=new CertificationRequest(info, algo,
> bitstring);
>
>
> Thank you,
>
>
> --
> Kasun Sanjeewa Perera
> UCSC
> University of Colombo
> Sri Lanka.


--
Djigzo open source email encryption

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Creating a PKCS#10 Certificate Request

Kasun Sanjeewa Perera

Hi,

I need a clarification. I am developing this using J2ME and BC Light Crypto API. The PKCS10CertificateRequest class is not in the Light API. How can I create a certification request in J2ME. Can anybody explain what is the need of followings.


//asn set
        DERSet asnset=new DERSet();
        //der bit strings
        DERBitString bitstring=new DERBitString();  // here also what to give argument as byte array for constructer

Thank you.






--
Kasun Sanjeewa Perera
UCSC
University of Colombo
Sri Lanka.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Creating a PKCS#10 Certificate Request

Sura
In reply to this post by Kasun Sanjeewa Perera
This is a sample code to generate a certificate request

/**
     * This method is used to generate private and public key for CA
     * use RSA algorithm and BC security provider
     * @return void   
     * @throws NoSuchProviderException
     * @throws NoSuchAlgorithmException
     * @throws java.lang.Exception
     */
    private void generateKeyPair()
    {
        try
        {
            //Add Security Provider BC
                       
            Provider provider = Security.getProvider("BC");
           
            //Security.addProvider(provider);           
            KeyPairGenerator  kpGen = KeyPairGenerator.getInstance("RSA" , provider);
           
            kpGen.initialize(2048, new SecureRandom());
            keyPair=kpGen.generateKeyPair();       
       
        }     
        catch(Exception err)
        {        
        }
    }
   
       
    /**
     * This method is used to generate certificate request to CA in PKCS10 format
     * @param  principal -principal for CA
     * @return void   
     * @throws SignatureException
     * @throws NoSuchProviderException
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeyException
     * @throws java.lang.Exception
     */
    private void generateCertRequest(String principal)
    {
        try
        {
            X500Principal subject= new X500Principal(principal);           
            request = new PKCS10CertificationRequest("SHA1withRSA",subject,keyPair.getPublic(),null,keyPair.getPrivate());
        }      
        catch(Exception err)
        {
        }
    }

/**********************************************************************
                cn        = txtCommonName.getText();                             //common Name
                ou        = txtOrganizationalUnit.getText();                     // Organization Unit
                o         = txtOrganization.getText();                           // Organization
                l          = txtLocality.getText();                                // Locality
                st        = txtState.getText();                                    //State
                c         = getCountry(cmbCountry.getSelectedItem().toString()); //Country
                principal = "CN="+cn+",OU="+ou+",O="+o+",L="+l+",ST="+st+",C="+c;
**************************************************************************/

From: Kasun Sanjeewa Perera <[hidden email]>
To: [hidden email]
Sent: Tuesday, June 23, 2009 5:58:22 PM
Subject: [dev-crypto] Creating a PKCS#10 Certificate Request

Hi,

I am new to bouncy castle. I wish to know how to create a PKCS#10 Certificate Request using bouncy castle in JAVA. Here is my code. But I don't know the meanings of highlighted methods. Can someone send me a example of Certificate Request Generation.

        AlgorithmIdentifier algo=new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption,new DERNull());

        //RSA key generation
        RSA rsa=new RSA();  // my rsa key generation class
        BigInteger bInt = new BigInteger("17");
        rsa.setKey(bInt, 1024, 100);
        RSAKeyParameters pubkey= rsa.getPublicKey();

        //key structure
        RSAPublicKeyStructure keystruct=new RSAPublicKeyStructure(pubkey.getModulus(), pubkey.getExponent());

        //subject key info
        SubjectPublicKeyInfo pubkeyinfo=new SubjectPublicKeyInfo(algo, keystruct);

        //X509 name
        X509Name name=new X509Name("C=LK,CN=kasun,O=UOC,OU=UCSC");

        //asn set
        DERSet asnset=new DERSet();
        //der bit strings
        DERBitString bitstring=new DERBitString();  // here also what to give as byte array for constructer

        CertificationRequestInfo info=new CertificationRequestInfo(name, pubkeyinfo, asnset);
        CertificationRequest Req=new CertificationRequest(info, algo, bitstring);


Thank you,


--
Kasun Sanjeewa Perera
UCSC
University of Colombo
Sri Lanka.

Loading...