如何使用makecert创建WCF接受的X509证书
任何人都可以为我提供一个关于如何创建自签名证书的示例,该证书将被以下代码接受:
ServiceHost svh = new ServiceHost(typeof(MyClass));
var tcpbinding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential, true);
//security
tcpbinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
svh.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new BWUserNamePasswordValidator();
svh.Credentials.UserNameAuthentication.UserNamePasswordValidationMode =UserNamePasswordValidationMode.Custom;
svh.Credentials.ServiceCertificate.Certificate = BookmarkWizSettings.TcpBindingCertificate;
....
svh.Open();
我已经使用过
makecert -pe myCertificate
并且
makecert -sv SignRoot.pvk -cy authority -r signroot.cer -a sha1 -n "CN=Dev Certification Authority" -ss my -sr localmachine
并且
makecert -r -pe -n "CN=Client" -ss MyApp -sky Exchange
我已经尝试使用 BouncyCastle 生成证书,但是每次我得到以下异常:
It is likely that certificate 'CN=Dev Certification Authority' may not have a
private key that is capable of key exchange or the process may not have access
rights for the private key. Please see inner exception for detail.
并且内部异常为空。
可能有一个技巧,但我不明白。
如何为我的 WCF 服务生成正确的证书?
Can anyone provide me with an example on how to create a self signed certificate, which would be accepted by the following code:
ServiceHost svh = new ServiceHost(typeof(MyClass));
var tcpbinding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential, true);
//security
tcpbinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
svh.Credentials.UserNameAuthentication.CustomUserNamePasswordValidator = new BWUserNamePasswordValidator();
svh.Credentials.UserNameAuthentication.UserNamePasswordValidationMode =UserNamePasswordValidationMode.Custom;
svh.Credentials.ServiceCertificate.Certificate = BookmarkWizSettings.TcpBindingCertificate;
....
svh.Open();
I've used
makecert -pe myCertificate
and
makecert -sv SignRoot.pvk -cy authority -r signroot.cer -a sha1 -n "CN=Dev Certification Authority" -ss my -sr localmachine
and
makecert -r -pe -n "CN=Client" -ss MyApp -sky Exchange
and I've tried to generate the certificate with BouncyCastle, but every time I'm getting following exception:
It is likely that certificate 'CN=Dev Certification Authority' may not have a
private key that is capable of key exchange or the process may not have access
rights for the private key. Please see inner exception for detail.
and the inner exception is null.
There's likely a trick to it, but I'm not getting it.
How do I generate a proper certificate for my WCF service??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下代码适用于框架 4.0:
首先很重要
在 LocalMachine 中手动安装您的证书作为受信任证书
为此,您只需从 Internet Explorer 打开服务器位置即可安装它。
第二个
响应服务器错误,因为自签名证书
The following code works for me for framework 4.0:
It is important first
to install your certificate manually as trusted certificate in your LocalMachine
In order to do this you can install it simply from internet explorer by opening the server location.
and second
to respond to the server error, because of the self sign certificate