Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (42 sloc) 1.6 KB
id title date author layout guid permalink video_type categories tags
391
Use a p12 certificate with Web Services / SSL in Java and CXF
2013-06-30 18:24:41 +0000
Marco Molteni
post
/2013/06/30/use-p12-certificate-with-web-services-in-java-and-cxf/
#NONE#
java
Java 6
Java EE
Uncategorized
Web Services
certificate
cxf
java
p12
security
web services

Problem : I need to access a webservice of a provider. The provider gave to me a .cert file and a .p12 file.

The private key p12 is not easy to manage in java. The default Key Store (cacert) doesn’t manage private keys.

I’m using apache cxf to access the webservice.

Solution:

  1. Create a new Key Store for your private key and import the p12 file
keytool -importkeystore -srckeystore privateKeyFile.p12 -srcstoretype PKCS12 -destkeystore personalKeyStore.jks

The .cert file should be imported in the cacert file:

http://docs.oracle.com/javase/1.5.0/docs/tooldocs/solaris/keytool.html

You can easily access the certificate and the personal key from cxf using the following configuration.

For the private.jks store you need two passwords:

One password to access the file private.jks: ‘storePassword’

One password to access the private key inside the private.jks: ‘personalKeyPassword’ the provider gave to you this password.

View the code on Gist.