首页 > 解决方案 > System.Security.Cryptography.Pkcs.EnvelopedCms.GetCspParams 返回异常“找不到对象或属性”。

问题描述

尝试解密文件时出现异常:

           var encData = File.ReadAllBytes(encFile);

           var file = File.ReadAllBytes(encFile);
        
           ContentInfo cinf = new ContentInfo(file);

           var ec = new EnvelopedCms(cinf);

           X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
           store.Open(OpenFlags.ReadOnly);

           ec.Decode(encData);

           ec.Decrypt(store.Certificates);

我完全知道 List 内部存在store.Certificates适当的证书,为什么抛出异常?在我添加新证书之前,这段代码已经工作了,除了哈希算法之外,与以前没有区别......

UPD:完整的调用堆栈异常是

   at System.Security.Cryptography.Pkcs.EnvelopedCms.GetCspParams(RecipientInfo recipientInfo, X509Certificate2Collection extraStore, CMSG_DECRYPT_PARAM& cmsgDecryptParam)
    at System.Security.Cryptography.Pkcs.EnvelopedCms.DecryptContent(RecipientInfoCollection recipientInfos, X509Certificate2Collection extraStore)
    at System.Security.Cryptography.Pkcs.EnvelopedCms.Decrypt(X509Certificate2Collection extraStore)

标签: c#.netcryptographyx509certificate

解决方案


此异常的原因 - 不支持的哈希算法 - 在俄罗斯标准 GOST R 34.11-2012 或 STREEBOG 中定义。所以因为我有 CryptoPro 许可证,所以我使用带有命令行参数的 cryptcp.exe ...


推荐阅读