[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [iaik-jce] Help: Creating CSR Error



I  have use the following and it worked fine:

   KeyPair key_pair=null;
   key_pair = generateKeyPair("RSA", "RSA", 1024);
   RSAPrivateKey rsa_private_key = (RSAPrivateKey) key_pair.getPrivate();
   RSAPublicKey rsa_public_key = (RSAPublicKey) key_pair.getPublic(); 
   try{
        FileOutputStream foP = new FileOutputStream("rsa_private_key.key");
        rsa_private_key.writeTo(foP);
        foP.close();
   } catch(Exception e){
       System.out.println("Error creating file!");
       e.printStackTrace();
   }
  
   Name subject = new Name();
   subject.addRDN(ObjectID.country, "AR");
   subject.addRDN(ObjectID.locality, "Rosario");
   subject.addRDN(ObjectID.organization ,"Orga");
   subject.addRDN(ObjectID.organizationalUnit ,"Sistemas");
   subject.addRDN(ObjectID.commonName ,"www.aaaa.com.ar");
   subject.addRDN(ObjectID.emailAddress ,"info@aaaa.com.ar");
   subject.addRDN(ObjectID.stateOrProvince ,"Santa Fe");
  
   
   try{

       CertificateRequest cert_request = new CertificateRequest(rsa_public_key, subject);
        cert_request.sign(AlgorithmID.md5WithRSAEncryption, rsa_private_key);
   
     
        FileOutputStream foC = new FileOutputStream("cert_request.gem");
        PemOutputStream pos = new PemOutputStream (foC, "-----BEGIN CERTIFICATE REQUEST-----", "-----END CERTIFICATE REQUEST-----");
   
        pos.write(cert_request.toByteArray(), 0, cert_request.toByteArray().length);
        pos.flush();
        foC.close();
        pos.close();
    } catch (Exception e){
       System.out.println("Error creating file!");
       e.printStackTrace();
    }

Marius Wong wrote:
000d01c0ae99$3b1d5020$f40a849e@MarsSign">
Hi all,
i have create a CSR in based64 format.but it can' be accepted by VersSign.
what can i do?
follows is the code.
 
i do insert the tab, -----BEGIN NEW CERTIFICATE REQUEST-----
and -----END NEW CERTIFICATE REQUEST-----
 
 
 
 KeyPairGenerator keyGen = KeyPairGenerator.getInstance(encodeAlg, proivder);
 keyGen.initialize(keyLen, new SecureRandom());
 KeyPair keyPair = keyGen.generateKeyPair();
 prvKey = keyPair.getPrivate();
 pubKey = keyPair.getPublic();
 
 Name subject = new Name();
 subject.addRDN(ObjectID.country, "AT");
 subject.addRDN(ObjectID.locality, "Graz");
 subject.addRDN(ObjectID.organization ,"TU Graz");
 subject.addRDN(ObjectID.organizationalUnit ,"IAIK");
 subject.addRDN(ObjectID.commonName ,"TestUser");
 
 CertificateRequest certReq = new CertificateRequest(pubKey, subject);
 certReq.sign(AlgorithmID.md5WithRSAEncryption, prvKey);
 System.out.print(certReq.toString());
 
 
 
 Base64OutputStream base64os = new Base64OutputStream(new FileOutputStream("test"));
 byte[] data = certReq.toString().getBytes();
 base64os.write(data); base64os.flush();
 base64os.close();
 
 if (certReq.verify())
 { System.out.print("vertify OK!"); }