-
Generate CSR using API problem??
Hi all ,
I have this piece of code below using JDK 1.3 and BouncyCastel Provider
//some other import ... i am using bouncyCastle Provider
import javax.crypto.Cipher;
import org.bouncycastle.jce.PKCS10CertificationRequest;
import org.bouncycastle.asn1.x509.X509Name;
public class test
{
public static void main(String []args) throws Exception
{
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
KeyStore ks=KeyStore.getInstance("JKS");
ks.load(new FileInputStream("test.keystore"),"one1234".toCharArray());
Enumeration e = ks.aliases();
X509Certificate c=null;
while(e.hasMoreElements())
{
String alias = e.nextElement().toString();
if(ks.isKeyEntry(alias))
{
c = (X509Certificate) ks.getCertificate(alias);
break;
}
}
String subject = c.getSubjectDN().getName();
X509Name xname = new X509Name(subject);
PrivateKey priv = (PrivateKey) ks.getKey("mykey","one1234".toCharArray());
PublicKey pub = (PublicKey) c.getPublicKey();
PKCS10CertificationRequest csr = new PKCS10CertificationRequest("MD5WithRSA",xname, pub,null,priv);
byte buf[] = csr.getEncoded();
FileOutputStream os = new FileOutputStream("request.crt");
OutputStreamWriter wr = new OutputStreamWriter(os);
wr.write("-----BEGIN NEW CERTIFICATE REQUEST-----\n");
wr.write(new sun.misc.BASE64Encoder().encode(buf));
wr.write("\n-----END NEW CERTIFICATE REQUEST-----\n");
wr.flush();
}
}
The coding Was OKAY and ran successfully...
The Problem is i want to get the same result as if i generate a csr using KEYTOOL utility...
BUT somehow i got different result , is it due because of signature algorithm or encoding??
Please help me ....
Thanks....
God Bless..
Similar Threads
-
Replies: 0
Last Post: 10-30-2002, 04:40 AM
-
By substring in forum VB Classic
Replies: 2
Last Post: 07-24-2001, 02:29 PM
-
By tyris in forum VB Classic
Replies: 6
Last Post: 02-01-2001, 02:08 AM
-
By Ayman in forum VB Classic
Replies: 8
Last Post: 04-03-2000, 08:13 PM
-
By Mike in forum VB Classic
Replies: 2
Last Post: 03-16-2000, 01:35 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks