Results 1 to 7 of 7
  1. #1
    koolking is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Exclamation How to use .cer file inside Java Code

    Can anyone tell me how to use .cer certificate file inside java code.

  2. #2
    pao
    pao is offline Member
    Join Date
    Jun 2008
    Posts
    43
    Rep Power
    0

    Default Re: How to use .cer file inside Java Code

    What do you want to do with it? Normally when I've worked with certificates in the past I just loaded them into a keystore\truststore and then referenced that in java. I think there is also a java keystore somewhere within the installation directories of Java.

    If you could provide a little more information it might make it easier to help you.

  3. #3
    jobi is offline Member
    Join Date
    Sep 2011
    Posts
    14
    Rep Power
    0

    Default Re: How to use .cer file inside Java Code

    I used .cer file to put a Digital certificate on my pdf file.
    I created .cer file by using cmd.

  4. #4
    faisalhameed is offline Member
    Join Date
    Jan 2010
    Location
    Lahore
    Posts
    5
    Rep Power
    0

    Default Re: How to use .cer file inside Java Code

    you can use the followng commad to convert .cer file to keystore

    1.keytool -import -keystore client.keystore -file WSS.cer
    2.Input password for your output file(say abc)

    This will create a file named client.keystore
    Then you can use it in your java code.

    System.setProperty("javax.net.ssl.trustStore", "client.keystore");
    System.setProperty("javax.net.ssl.trustStorePasswo rd","abc");

  5. #5
    koolking is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default Re: How to use .cer file inside Java Code

    There is a web service built in .Net and running on SSL. I am using axis client to connect to it. First I used a .jks certificate to connect to it. But now I have to use .cer file to connect. I need to be able to connect to the web service. I have used keytool for keystore generation but I am not able to connect to web service.

    I use
    keytool -import -keystore client.keystore -file WSS.cer
    to generate the keystore and use it in the code using

    System.setProperty("javax.net.ssl.keyStore", keystorePath);
    System.setProperty("javax.net.ssl.keyStorePassword ", password);

    System.setProperty("javax.net.ssl.trustStore", keystorePath);
    System.setProperty("javax.net.ssl.trustStorePasswo rd", password);

    But I am not able to connect to it.

    Can someone please guide me how to connect to it.

  6. #6
    faisalhameed is offline Member
    Join Date
    Jan 2010
    Location
    Lahore
    Posts
    5
    Rep Power
    0

    Default Re: How to use .cer file inside Java Code

    what does it means??
    "But I am not able to connect to it"
    What message/Exception you are getting?
    and you only need to set the following

    System.setProperty("javax.net.ssl.trustStore", keystorePath);
    System.setProperty("javax.net.ssl.trustStorePasswo rd", password);

    Don't use

    System.setProperty("javax.net.ssl.keyStore", keystorePath);
    System.setProperty("javax.net.ssl.keyStorePassword ", password);

  7. #7
    koolking is offline Member
    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    Default Re: How to use .cer file inside Java Code

    I have tried using it but I am getting the following exception


    org.apache.axis2.AxisFault: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderE xception: unable to find valid certification path to requested target
    at org.apache.axis2.AxisFault.makeFault(AxisFault.jav a:430)
    at org.apache.axis2.transport.http.AxisRequestEntity. writeRequest(AxisRequestEntity.java:98)
    at org.apache.commons.httpclient.methods.EntityEnclos ingMethod.writeRequestBody(EntityEnclosingMethod.j ava:499)
    at org.apache.commons.httpclient.HttpMethodBase.write Request(HttpMethodBase.java:2114)
    at org.apache.commons.httpclient.HttpMethodBase.execu te(HttpMethodBase.java:1096)
    at org.apache.commons.httpclient.HttpMethodDirector.e xecuteWithRetry(HttpMethodDirector.java:398)[INFO] Unable to sendViaPost to url[https://csr.pmex.com.pk/ncel.webserv...radedata.asmx]
    org.apache.axis2.AxisFault: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderE xception: unable to find valid certification path to requested target
    at org.apache.axis2.AxisFault.makeFault(AxisFault.jav a:430)
    at org.apache.axis2.transport.http.AxisRequestEntity. writeRequest(AxisRequestEntity.java:98)
    at org.apache.commons.httpclient.methods.EntityEnclos ingMethod.writeRequestBody(EntityEnclosingMethod.j ava:499)
    at org.apache.commons.httpclient.HttpMethodBase.write Request(HttpMethodBase.java:2114)
    at org.apache.commons.httpclient.HttpMethodBase.execu te(HttpMethodBase.java:1096)
    at org.apache.commons.httpclient.HttpMethodDirector.e xecuteWithRetry(HttpMethodDirector.java:398)
    at org.apache.commons.httpclient.HttpMethodDirector.e xecuteMethod(HttpMethodDirector.java:171)
    at org.apache.commons.httpclient.HttpClient.executeMe thod(HttpClient.java:397)
    at org.apache.commons.httpclient.HttpClient.executeMe thod(HttpClient.java:346)
    at org.apache.axis2.transport.http.AbstractHTTPSender .executeMethod(AbstractHTTPSender.java:560)
    at org.apache.axis2.transport.http.HTTPSender.sendVia Post(HTTPSender.java:199)
    at org.apache.axis2.transport.http.HTTPSender.send(HT TPSender.java:76)
    at org.apache.axis2.transport.http.CommonsHTTPTranspo rtSender.writeMessageWithCommons(CommonsHTTPTransp ortSender.java:400)
    at org.apache.axis2.transport.http.CommonsHTTPTranspo rtSender.invoke(CommonsHTTPTransportSender.java:22 5)
    at org.apache.axis2.engine.AxisEngine.send(AxisEngine .java:438)
    at org.apache.axis2.description.OutInAxisOperationCli ent.send(OutInAxisOperation.java:402)
    at org.apache.axis2.description.OutInAxisOperationCli ent.executeImpl(OutInAxisOperation.java:229)
    at org.apache.axis2.client.OperationClient.execute(Op erationClient.java:165)
    at org.tempuri.WSTradeDataStub.getFxRates(WSTradeData Stub.java:2151)
    at Driver2.main(Driver2.java:179)
    Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderE xception: unable to find valid certification path to requested target
    at com.sun.net.ssl.internal.ssl.Alerts.getSSLExceptio n(Alerts.java:174)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(S SLSocketImpl.java:1611)
    at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Ha ndshaker.java:187)
    at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Ha ndshaker.java:181)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.serv erCertificate(ClientHandshaker.java:1035)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.proc essMessage(ClientHandshaker.java:124)
    at com.sun.net.ssl.internal.ssl.Handshaker.processLoo p(Handshaker.java:516)
    at com.sun.net.ssl.internal.ssl.Handshaker.process_re cord(Handshaker.java:454)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRec ord(SSLSocketImpl.java:884)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.perform InitialHandshake(SSLSocketImpl.java:1112)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRe cord(SSLSocketImpl.java:623)
    at com.sun.net.ssl.internal.ssl.AppOutputStream.write (AppOutputStream.java:59)
    at java.io.BufferedOutputStream.flushBuffer(BufferedO utputStream.java:65)
    at java.io.BufferedOutputStream.flush(BufferedOutputS tream.java:123)
    at org.apache.axis2.transport.http.AxisRequestEntity. writeRequest(AxisRequestEntity.java:94)
    ... 18 more
    Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderE xception: unable to find valid certification path to requested target
    at sun.security.validator.PKIXValidator.doBuild(PKIXV alidator.java:285)
    at sun.security.validator.PKIXValidator.engineValidat e(PKIXValidator.java:191)
    at sun.security.validator.Validator.validate(Validato r.java:218)
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl. validate(X509TrustManagerImpl.java:126)
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl. checkServerTrusted(X509TrustManagerImpl.java:209)
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl. checkServerTrusted(X509TrustManagerImpl.java:249)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.serv erCertificate(ClientHandshaker.java:1014)
    ... 28 more
    Caused by: sun.security.provider.certpath.SunCertPathBuilderE xception: unable to find valid certification path to requested target
    at sun.security.provider.certpath.SunCertPathBuilder. engineBuild(SunCertPathBuilder.java:174)
    at java.security.cert.CertPathBuilder.build(CertPathB uilder.java:238)
    at sun.security.validator.PKIXValidator.doBuild(PKIXV alidator.java:280)
    ... 34 more

    at org.apache.commons.httpclient.HttpMethodDirector.e xecuteMethod(HttpMethodDirector.java:171)
    at org.apache.commons.httpclient.HttpClient.executeMe thod(HttpClient.java:397)
    at org.apache.commons.httpclient.HttpClient.executeMe thod(HttpClient.java:346)
    at org.apache.axis2.transport.http.AbstractHTTPSender .executeMethod(AbstractHTTPSender.java:560)
    at org.apache.axis2.transport.http.HTTPSender.sendVia Post(HTTPSender.java:199)
    at org.apache.axis2.transport.http.HTTPSender.send(HT TPSender.java:76)
    at org.apache.axis2.transport.http.CommonsHTTPTranspo rtSender.writeMessageWithCommons(CommonsHTTPTransp ortSender.java:400)
    at org.apache.axis2.transport.http.CommonsHTTPTranspo rtSender.invoke(CommonsHTTPTransportSender.java:22 5)
    at org.apache.axis2.engine.AxisEngine.send(AxisEngine .java:438)
    at org.apache.axis2.description.OutInAxisOperationCli ent.send(OutInAxisOperation.java:402)
    at org.apache.axis2.description.OutInAxisOperationCli ent.executeImpl(OutInAxisOperation.java:229)
    at org.apache.axis2.client.OperationClient.execute(Op erationClient.java:165)
    at org.tempuri.WSTradeDataStub.getFxRates(WSTradeData Stub.java:2151)
    at Driver2.main(Driver2.java:179)
    Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderE xception: unable to find valid certification path to requested target
    at com.sun.net.ssl.internal.ssl.Alerts.getSSLExceptio n(Alerts.java:174)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(S SLSocketImpl.java:1611)
    at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Ha ndshaker.java:187)
    at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Ha ndshaker.java:181)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.serv erCertificate(ClientHandshaker.java:1035)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.proc essMessage(ClientHandshaker.java:124)
    at com.sun.net.ssl.internal.ssl.Handshaker.processLoo p(Handshaker.java:516)
    at com.sun.net.ssl.internal.ssl.Handshaker.process_re cord(Handshaker.java:454)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRec ord(SSLSocketImpl.java:884)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.perform InitialHandshake(SSLSocketImpl.java:1112)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRe cord(SSLSocketImpl.java:623)
    at com.sun.net.ssl.internal.ssl.AppOutputStream.write (AppOutputStream.java:59)
    at java.io.BufferedOutputStream.flushBuffer(BufferedO utputStream.java:65)
    at java.io.BufferedOutputStream.flush(BufferedOutputS tream.java:123)
    at org.apache.axis2.transport.http.AxisRequestEntity. writeRequest(AxisRequestEntity.java:94)
    ... 18 more
    Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderE xception: unable to find valid certification path to requested target
    at sun.security.validator.PKIXValidator.doBuild(PKIXV alidator.java:285)
    at sun.security.validator.PKIXValidator.engineValidat e(PKIXValidator.java:191)
    at sun.security.validator.Validator.validate(Validato r.java:218)
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl. validate(X509TrustManagerImpl.java:126)
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl. checkServerTrusted(X509TrustManagerImpl.java:209)
    at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl. checkServerTrusted(X509TrustManagerImpl.java:249)
    at com.sun.net.ssl.internal.ssl.ClientHandshaker.serv erCertificate(ClientHandshaker.java:1014)
    ... 28 more
    Caused by: sun.security.provider.certpath.SunCertPathBuilderE xception: unable to find valid certification path to requested target
    at sun.security.provider.certpath.SunCertPathBuilder. engineBuild(SunCertPathBuilder.java:174)
    at java.security.cert.CertPathBuilder.build(CertPathB uilder.java:238)
    at sun.security.validator.PKIXValidator.doBuild(PKIXV alidator.java:280)
    ... 34 more

Similar Threads

  1. Replies: 6
    Last Post: 09-12-2011, 03:27 PM
  2. using java code inside javascipt-- in jsp
    By happy in forum Java Servlet
    Replies: 6
    Last Post: 06-15-2011, 06:58 PM
  3. Replies: 5
    Last Post: 05-25-2009, 10:03 PM
  4. search file inside Zip, Rar file
    By hungerToJava in forum New To Java
    Replies: 0
    Last Post: 03-21-2009, 09:36 AM
  5. Replies: 6
    Last Post: 02-06-2009, 09:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •