c# - 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)
解决方案
此异常的原因 - 不支持的哈希算法 - 在俄罗斯标准 GOST R 34.11-2012 或 STREEBOG 中定义。所以因为我有 CryptoPro 许可证,所以我使用带有命令行参数的 cryptcp.exe ...
推荐阅读
- php - Laravel Auth::user() always null
- json - How do I parse JSON key pair values in BigQuery?
- java - i see grey code in android studio. What is grey code mean?
- python - Docx file corrupted when adding an image with python docx
- javascript - How to save data from a planner in real time database using javascript?
- docker - docker-compose up -d send disconnect: Broken pipe
- amazon-web-services - Sync two different s3 buckets on different accounts on an ec2 instance
- python - 为什么 django 抛出完整性错误?
- jquery - 使用 jquery 将悬停标题添加到选项卡图像库
- java - 使用 Gmail Java API 更改 Gmail 中的默认签名