By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,804 Members | 1,364 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,804 IT Pros & Developers. It's quick & easy.

java.security.cert.CertificateException: Could not parse certificate: java.io.IOExcep

P: 17
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.security.*;
  3. import java.security.cert.*;
  4. import java.nio.charset.*;
  5. public class Cert
  6. {
  7.     public void export(java.security.cert.Certificate c) throws Exception
  8.     {
  9.         byte[] b=c.getEncoded();
  10.         FileOutputStream fos=new FileOutputStream("s.cer");
  11.         fos.write(b);
  12.         fos.close();
  13.         fos=new FileOutputStream("s.txt");
  14.         Writer w=new OutputStreamWriter(fos,Charset.forName("UTF8"));
  15.         w.write("-----BEGIN CERTIFICATE-------");
  16.         w.write(new sun.misc.BASE64Encoder().encode(b));
  17.         w.write("-----END CERTIFICATE-------");
  18.         w.flush();
  19.         fos.close();
  20.     }
  21.     public static void main(String args[]) throws Exception
  22.     {
  23.         Cert ce=new Cert();
  24.         FileInputStream fis=new FileInputStream("key.cer");
  25.         CertificateFactory cf=CertificateFactory.getInstance("X.509");
  26.         java.security.cert.Certificate c=cf.generateCertificate(fis);
  27.         ce.export(c);
  28.     }
  29. }
Apr 4 '13 #1

✓ answered by r035198x

There's a whole programmer guide on the subject http://docs.oracle.com/javase/6/docs...ProgGuide.html

Share this Question
Share on Google+
8 Replies


P: 17
Expand|Select|Wrap|Line Numbers
  1. C:\Cert>javac Cert.java
  2. Cert.java:16: warning: BASE64Encoder is internal proprietary API and may be removed in a future release
  3.                 w.write(newsun.misc.BASE64Encoder().encode(b));
  4.                                     ^
  5. 1 warning
  6.  
  7. C:\Cert>java Cert
  8. Exception in thread "main" java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: Empty input at sun.security.provider.X509Factory.engineGenerateCertificate(Unknown Source)at 
  9.  
  10. java.security.cert.CertificateFactory.generateCertificate(Unknown Source)
  11. at Cert.main(Cert.java:26)
  12.  
  13. Caused by: java.io.IOException: Empty input
  14.         ... 3 more
  15.  
  16. C:\Cert>
Apr 4 '13 #2

10K+
P: 13,264
Put more effort in posting your questions. Don't just post code and expect people to guess the problem you have. Also put effort in your program by reading the error messages that you get. The messages tell you what is wrong with your code.
Apr 4 '13 #3

P: 17
actually i try to solve it but it solving error


after running the code out should show an certificate page
Apr 4 '13 #4

P: 17
Could not pa
rse certificate: java.io.IOException: Empty input
Apr 4 '13 #5

10K+
P: 13,264
Ya so the message says empty input. Is your certificate empty?
Apr 4 '13 #6

P: 17
no

i had write some text in it.It's not empty
Apr 4 '13 #7

P: 17
is there any format to give the input into certificate file
Apr 4 '13 #8

10K+
P: 13,264
There's a whole programmer guide on the subject http://docs.oracle.com/javase/6/docs...ProgGuide.html
Apr 4 '13 #9

Post your reply

Sign in to post your reply or Sign up for a free account.