ssl - 如何在 mongodb SSL 中设置客户端证书验证

标签 ssl

我写了下面的代码来在 mongodb 的 SSL 中实现客户端认证验证。但是下面的代码抛出“ “System.Security.Cryptography.CryptographicException”类型的第一次机会异常发生在 mscorlib.dll 中。

String filename = "C://mongodb-cert.cert";

clientSettings.UseSsl = connectInfo.EnableSSL;

System.Security.Cryptography.X509Certificates.X509Certificate2 cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(文件名);

clientSettings.SslSettings.ClientCertificates = new List(){cert};

MongoClient mongoClient = new MongoClient( clientSettings );

任何人都可以查看代码并告诉我是什么导致代码抛出异常。

提前致谢。

--维布

最佳答案

可以是你的文件名吗?

String filename = "C://mongodb-cert.cert";

应该是:

String filename = "C:\\mongodb-cert.cert";

注意反斜杠 \\ 而不是正斜杠 //

关于ssl - 如何在 mongodb SSL 中设置客户端证书验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21537084/

相关文章:

Facebook 实时更新证书验证失败

负载均衡器背后的 Wordpress get_template_directory_uri()

c# - Azure 函数无法建立 SSL 连接

SSL 证书错误 : Invalid CA

ssl - 来自 Android 手机的 HTTPS 请求在 3G 和 4G 网络中失败,但在 2G 网络中工作正常

Tomcat clientAuth ="want"移除请求证书并处理请求

ssl - keystore 中的别名可以是 guid 吗?

java - 使用 java/netty 获得 handshake_failure,但使用 curl 成功获取相同的 https url

java - 从 Tomcat 运行时不在 CertificateRequest 中发送证书,但在从主类运行时发送证书

java - ldaptive 中信任证书的 "name"是什么?