使用JKS和/或PFX证书从C#客户端调用Java Web服务 [英] Invoking Java web service from C# client using JKS and/or PFX certificates
问题描述
我基本上需要确保对此服务的请求安全。
I basically need to secure my requests towards this service.
已为我提供了 JAR
测试客户和两个文件, trust.jks
和 Client.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屋!