在.NET中解密和检查签名时如何忽略系统存储?

IMi*_*Mil 5 .net c# cryptography ssl-certificate x509certificate

我需要在.NET应用程序中解密消息并验证签名.

我尝试使用EnvelopedCms.Decrypt(X509Certificate2Collection)和SignedCms.CheckSignature(X509Certificate2Collection,bool).这些方法运行良好,但是它们将证书集合视为附加证书; 他们总是使用来自系统商店的证书.

是否有标准方法使用提供的证书集合来解密和验证签名?我在系统存储区中有多个证书,如果来自客户端B,则应拒绝客户端A签名的消息.

fab*_*eal 0

您可能需要定义自定义验证方法:

检查此链接:http://8r13n.wordpress.com/2007/07/24/bypassing-certificate-validation-in-net/

虚拟实现将是这样的:

public static bool TrustAllCertificatesCallback(
        object sender, X509Certificate cert,
        X509Chain chain, SslPolicyErrors errors)
{
    return true;
}
Run Code Online (Sandbox Code Playgroud)

然后您将设置以下值ServerCertificateValidationCallback

// Call this at the start of your app
ServicePointManager.ServerCertificateValidationCallback =
            TrustAllCertificatesCallback;
Run Code Online (Sandbox Code Playgroud)

更新

如果您想检查 a 的发件人,SignedCms您可以使用该Certificates属性,该属性将保存客户端的证书。