问题描述
我有一个附件存储在数据库中,该附件的附件名称为smime.p7m
,其模仿类型为multipart/signed
。现在,我需要从已签名的p7m文件中提取附件,我希望可以使用Mimekit来实现此目的。我尝试了以下方法:
CryptographyContext.Register(typeof(WindowsSecureMimeContext));
try
{
using (MemoryStream ms = new MemoryStream(buf))
{
ApplicationPkcs7Mime p7m = new ApplicationPkcs7Mime(SecureMimeType.EnvelopedData,ms);
p7m.Verify(out attachment);
builder.Attachments.Add(attachment);
}
}
catch (Exception ex)
{
log.Error("Exception in smime",ex);
}
但是它失败,并在Verify行上出现system.invalidOperationException。
有什么想法吗?
解决方法
SecureMimeType.EnvelopedData
用于加密的数据,而不用于 signed 数据。您需要使用SecureMimeTYpe.SignedData
。