How do I sign a HTTP request with a X.509 certificate in Java?

Posted by Rune on Stack Overflow See other posts from Stack Overflow or by Rune
Published on 2010-05-26T19:24:01Z Indexed on 2010/05/26 21:01 UTC
Read the original article Hit count: 239

Filed under:
|
|
|

How do I perform an HTTP request and sign it with a X.509 certificate using Java?

I usually program in C#. Now, what I would like to do is something similar to the following, only in Java:

 private HttpWebRequest CreateRequest(Uri uri, X509Certificate2 cert) 
 {
     HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
     request.ClientCertificates.Add(cert);
     /* ... */
     return request;
 }

In Java I have created a java.security.cert.X509Certificate instance but I cannot figure out how to associate it to a HTTP request. I can create a HTTP request using a java.net.URL instance, but I don't seem to be able to associate my certificate with that instance (and I'm not sure whether using java.net.URL is even appropriate).

© Stack Overflow or respective owner

Related posts about java

Related posts about http