473,473 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to generate a "CertPath"?

When the generateCertPath line below is executed, I receive the
following message:

java.security.cert.CertificateException: unsupported encoding

This is a CA certificate from Verisign. What encoding should
I use?

-THanks

try {

// open an input stream to the file
FileInputStream fis = new FileInputStream(filename);

// instantiate a CertificateFactory for X.509
CertificateFactory cf = CertificateFactory.getInstance("X.509");

X509Certificate cert = (X509Certificate)cf.generateCertificate(fis);

//CertPath cp = cf.generateCertPath(fis, cert.getEncoded().toString());
CertPath cp = cf.generateCertPath(fis, "PKCS7");
}
catch (Exception e) {
e.printStackTrace();
}
Jul 17 '05 #1
2 6959
somebody <so**@body.com> wrote in message news:<pa***************************@body.com>...
When the generateCertPath line below is executed, I receive the
following message:

java.security.cert.CertificateException: unsupported encoding

This is a CA certificate from Verisign. What encoding should
I use?

-THanks

try {

// open an input stream to the file
FileInputStream fis = new FileInputStream(filename);

// instantiate a CertificateFactory for X.509
CertificateFactory cf = CertificateFactory.getInstance("X.509");

X509Certificate cert = (X509Certificate)cf.generateCertificate(fis);

//CertPath cp = cf.generateCertPath(fis, cert.getEncoded().toString());
CertPath cp = cf.generateCertPath(fis, "PKCS7");
}
catch (Exception e) {
e.printStackTrace();
}


Hello,

I encountered a message in one of Sun's Java forums that sounds
similar to what you are experiencing. The address of that message (and
the replies) is http://forum.java.sun.com/thread.jsp...message=666032.
For your convenience, I've restated the message/replies below:

* * *

Hi,

I am trying to generate a Certificate object using CertificateFactory,
and the message "java.security.cert.CertificateException: Unsupported
encoding" happenes . The certificate type I am using is X.509. The
encoded certificate was got from the browser (begin from "-----BEGIN
CERTIFICATE-----" and end with "-----END CERTIFICATE-----"). Here is
the segment of my code. Anyone knows what the problem is? Thanks in
advance.

/** Create an instance of the certificate factory */
java.security.cert.CertificateFactory cf =
java.security.cert.CertificateFactory.getInstance( "X.509");

/** Convert base 64 encoded certificate to a byte stream */
ByteArrayInputStream bais =
new ByteArrayInputStream(encodedCert.getBytes());

/** Generate certificate */
cf.generateCertificate(bais); // exception happend here

.. . .

Hi !

If it's framed like that I would guess you need to uuDecode it first,
before you can use it.

Have a look at http://java.sun.com/security/signExample/

That might help you.

.. . .

Hi,

Another possibility is that the cert is BASE64 encoded, you can base64
decode it using

String pemcert = "..."; // with the lines containing --- stripped off
byte[] certbytes = new sun.misc.BASE64Decoder().decodeBuffer(pemcert);

then create the CertificateFactory as before.

regards

Kevin

* * *

I hope this answer is helpful to you, and have a good day.

Jeff
www.javajeff.net
Jul 17 '05 #2
somebody <so**@body.com> wrote in message news:<pa***************************@body.com>...
When the generateCertPath line below is executed, I receive the
following message:

java.security.cert.CertificateException: unsupported encoding

This is a CA certificate from Verisign. What encoding should
I use?

-THanks

try {

// open an input stream to the file
FileInputStream fis = new FileInputStream(filename);

// instantiate a CertificateFactory for X.509
CertificateFactory cf = CertificateFactory.getInstance("X.509");

X509Certificate cert = (X509Certificate)cf.generateCertificate(fis);

//CertPath cp = cf.generateCertPath(fis, cert.getEncoded().toString());
CertPath cp = cf.generateCertPath(fis, "PKCS7");
}
catch (Exception e) {
e.printStackTrace();
}


Hello,

I encountered a message in one of Sun's Java forums that sounds
similar to what you are experiencing. The address of that message (and
the replies) is http://forum.java.sun.com/thread.jsp...message=666032.
For your convenience, I've restated the message/replies below:

* * *

Hi,

I am trying to generate a Certificate object using CertificateFactory,
and the message "java.security.cert.CertificateException: Unsupported
encoding" happenes . The certificate type I am using is X.509. The
encoded certificate was got from the browser (begin from "-----BEGIN
CERTIFICATE-----" and end with "-----END CERTIFICATE-----"). Here is
the segment of my code. Anyone knows what the problem is? Thanks in
advance.

/** Create an instance of the certificate factory */
java.security.cert.CertificateFactory cf =
java.security.cert.CertificateFactory.getInstance( "X.509");

/** Convert base 64 encoded certificate to a byte stream */
ByteArrayInputStream bais =
new ByteArrayInputStream(encodedCert.getBytes());

/** Generate certificate */
cf.generateCertificate(bais); // exception happend here

.. . .

Hi !

If it's framed like that I would guess you need to uuDecode it first,
before you can use it.

Have a look at http://java.sun.com/security/signExample/

That might help you.

.. . .

Hi,

Another possibility is that the cert is BASE64 encoded, you can base64
decode it using

String pemcert = "..."; // with the lines containing --- stripped off
byte[] certbytes = new sun.misc.BASE64Decoder().decodeBuffer(pemcert);

then create the CertificateFactory as before.

regards

Kevin

* * *

I hope this answer is helpful to you, and have a good day.

Jeff
www.javajeff.net
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Almoni | last post by:
Hi, I have a few .xsd files that include each other in the following way: <!-- lets call the main schema file AA.xsd and it includes BB.xsd inside it --> <xs:schema...
3
by: Garry Dawkins | last post by:
Hey Frank, I'm a novice with this taking over someone elses application. I'm attempting to add a dataset to a page. I have the query to populate the page and I have the walkthrough instructions. ...
1
by: jtsree | last post by:
I am Using (Windows XP) Visual Studio.net 2003 professional edition working on VB.net language. I am bulding a very very simple project in VB.net where i connect to Access Database by dragging...
9
by: Henk Verhoeven | last post by:
We are not alone! "Where other MDA tools are generating programmingcode, Codeless chooses not to generate code at all". OK, phpPeanuts is not an MDA tool (it has no fancy modeling GUI). But it...
4
by: Stephen | last post by:
I need to generate input XML for another application by serialising classes defined in an XSD document. The code below will generate the XML I require but I need to generate this in memory rather...
10
by: Mamuninfo | last post by:
Hello, Have any function in the DB2 database that can generate unique id for each string like oracle, mysql,sybase,sqlserver database. In mysql:- select md5(concat_ws("Row name")) from...
1
by: A Traveler | last post by:
Hello, i am having this problem. The exact error message is: "Unable to generate code for a value of type 'System.Web.UI.Page'. This error occurred while trying to generate the property value for...
5
by: pete | last post by:
Help, I can not find this data wizard in my toolbox under data. To generate a dataset 1.. From the Data menu, choose Generate DataSet. Tip If you do not see the Data menu, click in the...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
2
by: bthubbard | last post by:
This may not be the best group in which to post this. If there is a better location please direct me there. I have been experimenting with Sandcastle to generate CHM help file documentation for...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.