473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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

8 23278
neeru
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
r035198x
13,262 8TB
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
neeru
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
neeru
17
Could not pa
rse certificate: java.io.IOException: Empty input
Apr 4 '13 #5
r035198x
13,262 8TB
Ya so the message says empty input. Is your certificate empty?
Apr 4 '13 #6
neeru
17
no

i had write some text in it.It's not empty
Apr 4 '13 #7
neeru
17
is there any format to give the input into certificate file
Apr 4 '13 #8
r035198x
13,262 8TB
There's a whole programmer guide on the subject http://docs.oracle.com/javase/6/docs...ProgGuide.html
Apr 4 '13 #9

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

Similar topics

0
by: Derek | last post by:
what usually causes a java.security.NoSuchAlgorithmException? i am getting this while trying to run WebTest with SSL. so, if there is anyone out there using SSL and webtest i would appreciate...
4
by: Lorenzo | last post by:
hi you all, first of all apologies for having cross-posted this message but really i did not know where to post it. please let me know what ng you consider the most suitable for the described...
0
by: fabio | last post by:
Hi, I'm writing a program for PPC and I use IBM's Websphere Device Developper PPRO1.0 java VM. This vm is much smaller and simple than standard vm as it has to run on small devices as handhelds....
0
by: sarith sutha | last post by:
Hi Need a help on the above topic, how to pass a java object as parameter to the java stored procedure .Code snippets will be greatly appreciated , i came across udf/udts etc but still not able...
7
by: Mario | last post by:
I've been reading some Sun Java articles where they say Applets cannot import dlls and cannot write to disk. (This does NOT apply to applications, only to Applets.) Supposedly, this is NOT...
0
by: raja | last post by:
can we provide security for .war file in java. My project is over i created a war file and deploy it. My collegue knows about that. If he created one more java file add to that. to avoid that is...
6
by: kusuma chalasani | last post by:
hi.. i'm using msaccess database to retrive the data into an applet... during runtime i'm getting an error like java.security.AccessControlException:access denied(java.lang...
1
by: Smoothj | last post by:
Hello all, when connecting to an IRC server with my java applet some of my members get this error code. java.security.AccessControlException : access denied (java.net.SocketPermission...
0
by: mr man | last post by:
I try to play runescape and this came up......this comes up with all java java.security.PrivilegedActionException: java.io.FileNotFoundException: C:\Documents and Settings\HP_Owner\Application...
4
by: nano2 | last post by:
Hi , I am getting the following error when using java version 1.5 "java.security.NoSuchProviderException: no such provider: SunJSSE" Has anyone any ideas why i am getting this error .....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.