使用 JKS 和/或 PFX 证书从 C# 客户端调用 Java Web 服务 [英] Invoking Java web service from C# client using JKS and/or PFX certificates

查看:19
本文介绍了使用 JKS 和/或 PFX 证书从 C# 客户端调用 Java Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上需要保护我对这项服务的请求.

I basically need to secure my requests towards this service.

我得到了一个 JAR 测试客户端和两个文件,trust.jksClient.pfx,但我不知道如何使用它们:我知道 X509Certificate2 类以某种方式参与.

I've been provided a JAR test client and two files, trust.jks and Client.pfx, but I have no clue how to use them: I understand X509Certificate2 class is involved in some way.

执行测试客户端的命令行如下:

The command line to execute the test client is the following:

java -Djavax.net.ssl.trustStore=trust.jks -Djavax.net.ssl.trustStorePassword=******** -Djavax.net.ssl.trustStoreType=JKS -Djavax.net.ssl.keyStore=Client.pfx -Djavax.net.ssl.keyStoreType=pkcs12 -Djavax.net.ssl.keyStorePassword=******** -jar TestClient.jar https://myServiceurl

它可以工作,所以我既可以看到服务,又应该正确配置服务本身.

It works, so I can both see the service, and the service itself should be properly configured.

我的 C# 客户端(它针对 .NET 2.0)使用普通的 Web 引用来执行请求:

My C# client (it's targeting .NET 2.0) uses a normal Web Reference to perform requests:

wsReferenceClient service = new wsReferenceClient();
//certificate code here ?
//maybe service.ClientCertificates.Add(<X509Certificate2 object built somehow>); ?
service.MyRequest(myParameters);

应该正确设置服务器设置.

Server settings should be setup properly.

我摸索着 X509Certificate2 方法,但我想不出有意义的东西,所以回答你试过什么?"目前的问题是我一开始真的不知道该尝试什么".

I fumbled around with the X509Certificate2 methods but I can't come out with something that makes sense, so the answer to the 'what have you tried?' question at the moment is 'I don't really know what to try in the first place'.

任何帮助将不胜感激.

推荐答案

原来我不需要对 JKS 文件做任何事情.

Turns out I don't need to do anything with the JKS file.

wsReferenceClient service = new wsReferenceClient();
X509Certificate2 cert = new X509Certificate2();
cert.Import("Client.pfx", "<the password>", DefaultKeySet);
service.ClientCertificates.Add(cert);
service.MyRequest(myParameters);

这允许我的 HTTPS 请求成功通过.

This allows my HTTPS requests to go through successfully.

这篇关于使用 JKS 和/或 PFX 证书从 C# 客户端调用 Java Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆