FindBySubjectName vs FindBySubjectDistinguishedName

FindBySubjectName vs FindBySubjectDistinguishedName


FindBySubjectName : The findValue parameter for the Find method must be a string representing the subject name of the certificate. This is a less specific search than that provided by theFindBySubjectDistinguishedName enumeration value. Using the FindBySubjectName value, the Find method performs a case-insensitive string comparison using the supplied value. For example, if you pass "MyCert" to the Find method, it will find all certificates with the subject name containing that string, regardless of other subject values. Searching by distinguished name is a more precise search.


FindBySubjectDistinguishedName:The findValue parameter for the Find method must be a string representing the subject distinguished name of the certificate. This is a more specific search than that provided by theFindBySubjectName enumeration value. Using the FindBySubjectDistinguishedName value, the Find method performs a case-insensitive string comparison for the entire distinguished name. Searching by subject name is a less precise search.

`X509Certificate2Collection` 是 .NET Framework 中用于管理证书集合的类。在 dotnetty 中,我们可以使用 `X509Certificate2Collection` 来加载一个或多个证书,并将其用于 SSL/TLS 连接。 以下是一个简单的示例,演示如何使用 `X509Certificate2Collection` 加载单个证书: ```csharp // 加载证书 var cert = new X509Certificate2("mycert.pfx", "password"); // 将证书添加到集合中 var certCollection = new X509Certificate2Collection(); certCollection.Add(cert); // 使用证书集合创建 SslStream var sslStream = new SslStream(stream, false); sslStream.AuthenticateAsServer(certCollection, false, SslProtocols.Tls12, true); ``` 在上面的示例中,我们使用 `X509Certificate2` 类加载 `mycert.pfx` 证书,并将其添加到 `X509Certificate2Collection` 实例 `certCollection` 中。最后,我们使用 `AuthenticateAsServer` 方法创建一个 `SslStream` 并使用证书集合进行身份验证。 当然,我们也可以从其他来源加载证书,并将它们添加到 `X509Certificate2Collection` 中。例如,我们可以使用 `X509Store` 类从系统证书存储中加载证书: ```csharp // 从系统证书存储中加载证书 var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly); var certs = store.Certificates.Find(X509FindType.FindBySubjectName, "mycert.com", true); var certCollection = new X509Certificate2Collection(certs); store.Close(); ``` 在上面的示例中,我们使用 `X509Store` 类从当前用户的证书存储中加载名为 `mycert.com` 的证书,并将它们添加到 `X509Certificate2Collection` 实例 `certCollection` 中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值