【发布时间】:2022-01-10 08:42:26
【问题描述】:
我正在尝试解密并验证我使用 C# 从客户端获得的 PKCS7 响应。 最初我尝试封装和签名我的有效载荷并关注the answer mentioned here.
现在我再次在 PKCS7 中得到响应,并且在解密和验证响应时遇到了问题。
我尝试使用 EnvelopedCMS:
ecms.Decode(Convert.FromBase64String(payloadContent));
ecms.Decrypt(new X509.X509Certificate2Collection { _signerCert });
string decodedContent = Encoding.UTF8.GetString(ecms.ContentInfo.Content);
这里 _signerCert 是我自己的带有私钥的证书。
我可以在 decodedContent 中看到我需要的响应以及一些客户信息和一些未知的 ASCII 字符。
有谁知道如何实现对传入响应的解密和验证?
找到的解决方案:
我按照@bartonjs 的建议使用了这样的 SignedCms
SignedCms signedCMS = new SignedCms();
signedCMS.Decode(ecms.ContentInfo.Content);
【问题讨论】:
-
如果你通过签名运行它,然后在构建它时加密,你将通过解密运行它,然后在收到它时验证。在这里,您只通过解密运行它。
-
我现在应该从上面使用什么参数来验证它?
-
假设您按照链接帖子的说明进行操作,现在您可以将内容发送到 SignedCms.Decode。
-
SignedCms signedCMS = new SignedCms();signedCMS.Decode(ecms.ContentInfo.Content);成功了。非常感谢。
标签: c# .net cryptography x509certificate bouncycastle