如何解决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);
我完全知道列表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)
解决方法
此异常的原因-不支持的哈希算法-在俄罗斯标准GOST R 34.11-2012或STREEBOG中定义。因此,因为我拥有CryptoPro许可证,所以我将cryptcp.exe与命令行参数一起使用...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。