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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neeru
    New Member
    • Mar 2013
    • 17

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

    Code:
    import java.io.*;
    import java.security.*;
    import java.security.cert.*;
    import java.nio.charset.*;
    public class Cert
    {
    	public void export(java.security.cert.Certificate c) throws Exception
    	{
    		byte[] b=c.getEncoded();
    		FileOutputStream fos=new FileOutputStream("s.cer");
    		fos.write(b);
    		fos.close();
    		fos=new FileOutputStream("s.txt");
    		Writer w=new OutputStreamWriter(fos,Charset.forName("UTF8"));
    		w.write("-----BEGIN CERTIFICATE-------");
    		w.write(new sun.misc.BASE64Encoder().encode(b));
    		w.write("-----END CERTIFICATE-------");
    		w.flush();
    		fos.close();
    	}
    	public static void main(String args[]) throws Exception
    	{
    		Cert ce=new Cert();
    		FileInputStream fis=new FileInputStream("key.cer");
    		CertificateFactory cf=CertificateFactory.getInstance("X.509");
    		java.security.cert.Certificate c=cf.generateCertificate(fis);
    		ce.export(c);
    	}
    }
    Last edited by neeru; Apr 4 '13, 06:32 AM. Reason: C:\Cert>java Cert Exception in thread "main" java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: Empty input at sun.security.provider.X509Fa
  • neeru
    New Member
    • Mar 2013
    • 17

    #2
    Code:
    C:\Cert>javac Cert.java
    Cert.java:16: warning: BASE64Encoder is internal proprietary API and may be removed in a future release
                    w.write(newsun.misc.BASE64Encoder().encode(b));
                                        ^
    1 warning
    
    C:\Cert>java Cert
    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 
    
    java.security.cert.CertificateFactory.generateCertificate(Unknown Source)
    at Cert.main(Cert.java:26)
    
    Caused by: java.io.IOException: Empty input
            ... 3 more
    
    C:\Cert>

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      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.

      Comment

      • neeru
        New Member
        • Mar 2013
        • 17

        #4
        actually i try to solve it but it solving error


        after running the code out should show an certificate page

        Comment

        • neeru
          New Member
          • Mar 2013
          • 17

          #5
          Could not pa
          rse certificate: java.io.IOExcep tion: Empty input

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Ya so the message says empty input. Is your certificate empty?

            Comment

            • neeru
              New Member
              • Mar 2013
              • 17

              #7
              no

              i had write some text in it.It's not empty

              Comment

              • neeru
                New Member
                • Mar 2013
                • 17

                #8
                is there any format to give the input into certificate file

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

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

                  Comment

                  Working...