Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

write a certificate into a .cer file

843810May 21 2004 — edited May 24 2004
Hello, everyone,
With all of your help, I can programablely generate my own self-signed X509certificate by BC now. Thanks a lot!
But after that, I am willing to store it in a .cer file, and this .cer file should have the same type of the '.cer' file which I can get from keytool, for example: typing 'keytool -export -keystore stanstore -alias signLegal -file StanSmith.cer', I can get a self-signed certificate file .cer from a keystore. I need the .cer file I am going to generate is exactly the same as this one(StanSmith.cer). (of course, the content maybe different, but the type should be the same)
Is there anyone who can give some help?

This is what I have tried by myself:
...
//generate a certificate
        X509Certificate certificate =  certificateGenerator.generateX509Certificate(privatekey);

//write this certificate into a .cer file named certi.cer
        FileOutputStream fos = new FileOutputStream("certi.cer");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        byte[] cerbytearray = certificate.toString().getBytes();
        bos.write(cerbytearray, 0, cerbytearray.length);
        bos.flush();
        fos.close();
after execute, I opened this certi.cer using notepad, following is what I saw in the notepad:

[0] Version: 1
SerialNumber: 1
IssuerDN: CN=SomeName
Start Date: Fri May 21 14:28:03 EDT 2004
Final Date: Sat May 21 14:28:03 EDT 2005
SubjectDN: CN=SomeName
Public Key: RSA Public Key
modulus: 9461abee32aea82d115cdd976df26e9e18e28e5a564b9a19adcdb9346127219217ad32e8ec262a97c61d6be459bb3c8ca924a62ed3b9af325d31c2f3c0390374f33496c26f7dcfa69601f99e9339b227f56271a93af120a41c3aba247ba445d4fb16efb0bd72bb9858c25e5235a9db877673e14a7f333f9105a17b3b10198379
public exponent: 3

Signature Algorithm: SHA1WithRSAEncryption
Signature: 3cb694fa3e55bfb4415be4ec568f4834a21705e6
723e760a347c250758b5401ef399c6902327cabf
2463211bca851b7e45d049b37efb347c992150b3
56b14a8b57286e658bbac6b720c29559265af54f
4b9fdfd23f0b3641729ebfddc30800394fa4168a
0ef4eb17d499eba848d8d9cd1d1dd0b6984e19b0
650ee25846b17ae2


This 'certi.cer' is not the type of 'StanSmith.cer' which I got from a keystore using keytool, because when I tried to use notepad to open 'StanSmith.cer', some messy stuff showed up, not a clear information like 'certi.cer' does. So, I thought the type of 'certi.cer' may be base64, but, there is no start and end lines either. I am really confused.
Sorry for letting you read so much, the only purpose of that is to make my situation clear. In a word, I just want to know how to write a certificate into a .cer file which has the same type of 'StanSmith.cer'.
Thank you very much!

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 21 2004
Added on May 21 2004
2 comments
279 views