• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing a digital certificate into a .cer file

 
hossein arabi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everybody
I am stuck with writing a generated certificate into a file(.cer). I tried many ways but when I want to insert it into the browser it will give error that it is a invalid type.
I don know whether I should convert to any type like PKCS12 or not then write it to a file or how to correctly write it.
I will be really thankful if any one can show me a sample code.
Thank you
hossein.

 
Carey Evans
Ranch Hand
Posts: 225
Debian Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have an X509Certificate object, you can just write the bytes from its getEncoded() method to a FileOutputStream. Sometimes .cer files are base64-encoded PEM files, though, in which case you'd use something like Apache Commons Codec with the appropriate header and footer:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic