问题描述
尝试解密文件时出现异常:
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与命令行参数一起使用...